Hello, I wrote this small function that reads an image file and copies parts of a that image into picture boxes which are added to a panel. This function works the way I wanted it to work for MOST pictures, however, for some large images, it doesn't. Sometimes the image inside the picture boxes is displayed like half the size it should be.
I wonder if someone could tell me why that is.
Thanks in advance
This is what I have:
I wonder if someone could tell me why that is.
Thanks in advance
This is what I have:
Code:
void readpic()
{
openFileDialog1.ShowDialog();
Image img = Image.FromFile(openFileDialog1.FileName.ToString());
Bitmap bmp = (Bitmap)img;
PictureBox[] px;
int counter = 0;
px = new PictureBox[(img.Size.Width / 64)];
for (int p = 0; p < (img.Size.Height / 64); p++)
for (int i = 0; i < (img.Size.Width / 64); i++)
{
{
Bitmap bmp2 = new Bitmap(64, 64);
Rectangle rect = new Rectangle();
rect.Height = 64;
rect.Width = 64;
rect.X = 0 + i * 64;
rect.Y = 0 + p * 64;
bmp2 = CopyBitmap(bmp, rect);
px[i] = new PictureBox();
px[i].Name = counter.ToString();
px[i].Tag = px[i].Name;
px[i].BorderStyle = BorderStyle.Fixed3D;
px[i].Height = 64;
px[i].Width = 64;
px[i].Image = bmp2;
px[i].Left = i * 64;
px[i].Location = new Point(1 + i * 64, 1 + p * 64);
px[i].Click +=new EventHandler(Form1_Click);
panel1.Controls.Add(px[i]);
counter++;
}
}
}
Comment