pictureboxes on panel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slewrate
    New Member
    • Jun 2008
    • 2

    pictureboxes on panel

    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:

    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++;
     
    }
    }
     
    }
    Last edited by DrBunchman; Jun 14 '08, 04:30 PM. Reason: Added code tags - Please use the # button
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Why don't you just use the .GetThumbnail() function to do the resizing for you?
    Or is that contained with your CopyBitmap function?

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Does this run just they way you entered it here?
      I have my doubts about lines 12-15...
      12. for loop declaration
      13. for loop declaration
      14. {
      15. {

      Shouldn't this be...
      12. for loop
      13. {
      14. for loop
      15. {

      I'm just wondering if the way posted works, is legal and does something different or interesting from the 'normal' or 'other' way to do nested loops that I suggested.

      Comment

      • slewrate
        New Member
        • Jun 2008
        • 2

        #4
        I changed the position of the braces but it doesn't have an effect.

        Comment

        Working...