I have the attached code which performs a pretty cool job of taking three swaths of a picturebox, then pastes them together as a new image. The problem is that the image size is changing, but I need it to be the same.
See the attached image file. Notice the button on the right is taller than theone on the left. It was made with the code below.
I need to recreate the swaths exactly.
Let me know what I can change in the code to do that.
void CutImage(PictureBox pictureBox1, PictureBox pictureBox2)
Image sourceImage = pictureBox1.Image;
int leftWidth = sourceImage.Width * 15 / 100;
Rectangle leftSwath = new Rectangle(0, 0, leftWidth, sourceImage.Height);
int centerWidth = sourceImage.Width * 15 / 100;
Rectangle centerSwath = new Rectangle((sourceImage.Width - centerWidth) / 2, 0, centerWidth, sourceImage.Height);
int rightWidth = sourceImage.Width * 15 / 100;
Rectangle rightSwath = new Rectangle(sourceImage.Width - rightWidth, 0, sourceImage.Width * 15 / 100, sourceImage.Height);
Bitmap targetBitmap = new Bitmap(leftWidth + centerWidth + rightWidth, sourceImage.Height);
using (Graphics g = Graphics.FromImage(targetBitmap))
g.DrawImage(sourceImage, 0, 0, leftSwath, GraphicsUnit.Pixel);
g.DrawImage(sourceImage, leftWidth, 0, centerSwath, GraphicsUnit.Pixel);
g.DrawImage(sourceImage, leftWidth + centerWidth, 0, rightSwath, GraphicsUnit.Pixel);
pictureBox2.Image = targetBitmap;