InterpolationMode HighQualityBicubic在调整大小的图像边缘引入伪影 [英] InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images

查看:1824
本文介绍了InterpolationMode HighQualityBicubic在调整大小的图像边缘引入伪影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一些漂亮的股票标准C#代码来调整图像的大小,并将其放置在彩色背景上

 图像imgToResize =图像.FromFile(@ Dejeuner.jpg); 
尺寸大小=新尺寸(768,1024);
位图b =新位图(size.Width,size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.Green,0,0,size.Width,size.Height);

g.DrawImage(imgToResize,new Rectangle(0,150,768,570));
b.Save(sized_HighQualityBicubic.jpg);



这听起来像是一个bug吗?我可以理解为什么颜色会混合在调整大小的图像的顶部。但混合左/右边缘的颜色没有意义。有谁知道修复以防止这些文物?



更新:这里的评论非常类似: GDI + InterpolationMode

无耻地从这个问题解除答案,我发现这个问题解决了它:

  using(ImageAttributes wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY );
g.DrawImage(input,rect,0,0,input.Width,input.Height,GraphicsUnit.Pixel,wrapMode);
}


Using some pretty stock standard C# code to resize an image, and place it on a coloured background

Image imgToResize = Image.FromFile(@"Dejeuner.jpg");
Size size = new Size(768, 1024);
Bitmap b = new Bitmap(size.Width, size.Height);

Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height);

g.DrawImage(imgToResize, new Rectangle(0,150,768, 570));
b.Save("sized_HighQualityBicubic.jpg");

The result has a funny artefact in the 0th and 1st columns of pixels. The 0th column appears to be mixed with the background colour, and the 1st column has been made lighter.

See the top left corner zoomed for high quality bicubic and bicubic.

..and HighQualityBilinear

This forum post appears to be someone with the same problem: DrawImage with sharp edges

The sounds like a bug to me? I can understand why the colours would mix at the top of the resized image. But mixing the colours on the left / right edges doesn't make sense. Does anyone know of a fix to prevent these artefacts?

Update: very similar conversation going on in the comments here: GDI+ InterpolationMode

解决方案

Shamelessly lifting the answer from this question, I found this fixes it:

using (ImageAttributes wrapMode = new ImageAttributes())
{
    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
    g.DrawImage(input, rect, 0, 0, input.Width, input.Height, GraphicsUnit.Pixel, wrapMode);
}

这篇关于InterpolationMode HighQualityBicubic在调整大小的图像边缘引入伪影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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