I'm having a problem using this function to divide an image into multiple pieces and moving them a little bit.
The problem is that in the result the height of the rectangles is different from the "node_height" variable.
here is a testing image: measure.jpg and the result: measured.jpg in this image I used "node_height = 100". It was supposed to cut all the circles.
the code:
private void button2_Click(object sender, EventArgs e)
{
bmp = new Bitmap(source.Width, source.Height);
bmp.SetResolution(source.HorizontalResolution, source.VerticalResolution);
int node_height = trackBar1.Value;
int shift = trackBar2.Value;
int image_width = bmp.Width;
int image_height = bmp.Height;
double division = image_height / node_height;
int nodes = Convert.ToInt32(division);
Graphics g = Graphics.FromImage(bmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
g.PageScale = 1;
g.PageUnit = GraphicsUnit.Pixel;
g.Clear(Color.Transparent);
for(var i = 0; i < nodes; i++) {
int new_shift = RandomNumber(0,shift);
int x = 0;
int y = node_height * i;
int w = image_width;
int h = node_height;
Rectangle source_rect = new Rectangle(x, y, w, h);
Rectangle dest_rect = new Rectangle(new_shift, y, w, h);
g.DrawImage(source, dest_rect, source_rect, GraphicsUnit.Pixel);
}
MessageBox.Show("Done!");
pictureBox1.Image = bmp;
}