本文介绍了C#调整大小的图像有黑边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在.NET中使用的图像缩放的问题。我用的是标准的显卡类型来调整图像一样在这个例子中:
I have a problem with image scaling in .NET. I use the standard Graphics type to resize images like in this example:
public static Image Scale(Image sourceImage, int destWidth, int destHeight)
{
Bitmap toReturn = new Bitmap(sourceImage, destWidth, destHeight);
toReturn.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
using (Graphics graphics = Graphics.FromImage(toReturn))
{
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(sourceImage, 0, 0, destWidth, destHeight);
}
return toReturn;
}
不过,我有一个大问题,调整大小的图像:他们有灰色和黑色的边框,这是非常重要的是要具有图像没有他们
But I have a big problem with resized images: they have gray and black borders and it's extremely important to make have images without them.
为什么他们会出现什么我可以做,使他们消失?
Why do they appear and what I can to do make them disappear?
示例输出:
推荐答案
尝试:
graphic.CompositingMode = CompositingMode.SourceCopy;
这篇关于C#调整大小的图像有黑边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!