使用 C# 图形类调整图像大小时出现质量问题
我正在将小图像(例如 20x25)调整为较大图像(例如 150x170)。 我的问题不在于质量,正如预期的那样,质量有些模糊。我的问题是,边框是在图像的右侧和底部创建浅色边框。有没有办法可以将其删除?
我的代码如下:
using (Graphics g = Graphics.FromImage((Image)ResizedImage))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(OrigImage, new Rectangle(0, 0, Width, Height),
new Rectangle(0, 0, OrigCImage.Width, OrigImage.Height), GraphicsUnit.Pixel);
}
谢谢!
I am resizing an small images (eg 20x25) to larger images (eg 150x170).
My problem is not about quality, which as expected is has some blurring. My problem is that a border is that a light colour border is being created on the right hand side and bottom of the image. Is there a way that this can be removed?
My code is the following:
using (Graphics g = Graphics.FromImage((Image)ResizedImage))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(OrigImage, new Rectangle(0, 0, Width, Height),
new Rectangle(0, 0, OrigCImage.Width, OrigImage.Height), GraphicsUnit.Pixel);
}
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将此语句添加到您的代码中:
您现在将获得所有 4 个面都同样“亮”的图像。我认为这并不能真正解决你的问题。但这是不可避免的,插值器只是用完位图边缘的可用像素来做出更好的猜测。
您最好将 PixelOffsetMode 保留其原始设置,并故意将图像绘制得太大,以便边缘效果不可见。
这看起来不错:
Add this statement to your code:
You'll now get an image that is equally "light" on all 4 sides. That doesn't really solve your problem I would assume. But it is fairly inevitable, the interpolator simply runs out of usable pixels at the edges of the bitmap to make a better guess.
You might be better off by leaving the PixelOffsetMode at its original setting and intentionally drawing the image too large so the edge effects are not visible.
This looked good:
也许尝试添加
Maybe try adding