Skip to content

Instantly share code, notes, and snippets.

@mariusz
Created January 21, 2009 11:25
Show Gist options
  • Select an option

  • Save mariusz/49944 to your computer and use it in GitHub Desktop.

Select an option

Save mariusz/49944 to your computer and use it in GitHub Desktop.
public void AddGrid()
{
this.Picture = new Bitmap(this.pictureBox2.Image);
double scaleX = 1.0;
double scaleY = 1.0;
if (this.OrginalSizeX > this.OrginalSizeY)
{
scaleY = this.OrginalSizeY / this.OrginalSizeX;
}
else if (this.OrginalSizeX < this.OrginalSizeY)
{
scaleX = this.OrginalSizeX / this.OrginalSizeY;
}
float pixelWidth = (float)(scaleX * MaxHeightAndWidth);
float pixelHeight = (float)(scaleY * MaxHeightAndWidth);
if (this.view.mesh == null)
return;
int numberOfElementsX = this.view.mesh[0].Length;
int numberOfElementsY = this.view.mesh.Length;
float divX = pixelWidth / (numberOfElementsX - 1);
float divY = pixelHeight / (numberOfElementsY - 1);
Bitmap bmp = new Bitmap(this.pictureBox2.Image);
Graphics gr = Graphics.FromImage(bmp);
Pen pen = Pens.White;
for (int i = 0; i < numberOfElementsY - 1; i++)
{
float localDivY0 = (float)Bottom - (i * divY);
float localDivY1 = (float)Bottom - ((i + 1) * divY);
for (int j = 0; j < numberOfElementsX - 1; j++)
{
float localDivX0 = (float)Left + (j * divX);
float localDivX1 = (float)Left + ((j +1 ) * divX);
gr.DrawLine(pen, localDivX0, localDivY0, localDivX1, localDivY0);
gr.DrawLine(pen, localDivX0, localDivY0, localDivX0, localDivY1);
gr.DrawLine(pen, localDivX0, localDivY1, localDivX1, localDivY1);
gr.DrawLine(pen, localDivX1, localDivY1, localDivX1, localDivY0);
gr.DrawLine(pen, localDivX0, localDivY1, localDivX1, localDivY0);
}
}
gr.Save();
this.pictureBox2.Image = bmp;
this.pictureBox2.Refresh();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment