放大图片框时图像变得模糊 [英] image getting blurred when enlarging picture box

查看:76
本文介绍了放大图片框时图像变得模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发图像处理应用程序.要缩放图像,请放大PictureBox.但是放大之后,我得到了下面的图像.

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

但是我想要下图所示的结果

But I want result like below image

这是我的代码:

      picturebox1.Size = new Size((int)(height * zoomfactor), (int) 
      (width* zoomfactor));
      this.picturebox1.Refresh();

推荐答案

PictureBox本身将始终创建漂亮且流畅的版本.

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;

然后就不会模糊了.

示例:

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;
}

当然,您需要避免将PBox设置为Sizemode Zoom或Stretch!

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

这篇关于放大图片框时图像变得模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆