Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing an application for image processing. To zoom the image, I enlarge PictureBox. But after enlarging I get below image as result.

Application Output Image

But I want result like below image

enter image description here

Here is my Code :

      picturebox1.Size = new Size((int)(height * zoomfactor), (int) 
      (width* zoomfactor));
      this.picturebox1.Refresh();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

The PictureBox by itself will always create a nice and smooth version.

To create the effect you want you need to draw zoomed versions yourself. In doing this you need to set the

 Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;

Then no blurring will happen..

Example:

enter image description here

private void trackBar1_Scroll(object sender, EventArgs e)
{
    Bitmap bmp = (Bitmap)pictureBox1.Image;
    Size sz = bmp.Size;
    Bitmap zoomed = (Bitmap)pictureBox2.Image;
    if (zoomed != null) zoomed.Dispose();

    float zoom = (float)(trackBar1.Value / 4f + 1);
    zoomed = new Bitmap((int)(sz.Width * zoom), (int)(sz.Height * zoom));

    using (Graphics g = Graphics.FromImage(zoomed))
    {
      if (cbx_interpol.Checked) g.InterpolationMode = InterpolationMode.NearestNeighbor;
      g.PixelOffsetMode = PixelOffsetMode.Half;

      g.DrawImage(bmp, new Rectangle( Point.Empty, zoomed.Size) );
    }
    pictureBox2.Image = zoomed;
}

Of course you need to avoid setting the PBox to Sizemode Zoom or Stretch!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...