How to zoom in on a image with Zoom button?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrcw
    New Member
    • Nov 2008
    • 82

    How to zoom in on a image with Zoom button?

    Hi, Im trying to zoom in on an image. First I make a .bmp from the picturebox.imag e the make the.bmp bigger the put the new .bmp back into the picturebox. All this does is make my image disappear.Why?

    Code:
      private void btnZoomIn_Click(object sender, EventArgs e)
            {
                Bitmap a = new Bitmap(pictureBox1.Image.Height * 2, pictureBox1.Image.Width * 2);  
                pictureBox1.Image = a; 
               
            }
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    The reason that your Bitmap disappears is because you just constructed a blank Bitmap with a specific size. None of the data in the original bitmap is being used. The constructor you want to use is.

    Code:
    Size newSize = new Size(pictureBox1.Image,Width *2,pictureBox1.Image.Height *2 );
    Bitmap a = new Bitmap(pictureBox1.Image,newSize);
    This will scale your original bitmap up to that size

    Comment

    • mrcw
      New Member
      • Nov 2008
      • 82

      #3
      thanks for that. Why doesn't it work when scalar = 50 instead of 2?

      Comment

      Working...