我有一个高质量的大图像(根据我的需要),我需要调整到小尺寸(30 x 30px),我用graphic.DrawImage调整它的大小。但是当我调整大小时,它会变得模糊不清。 我也尝试过CompositingQuality和InterpolationMode,但一切都很糟糕。
例如,我正在尝试的质量。
我的结果
被修改 图标的图像我画自己,也许它会更好地绘制它而不调整大小?
EDIT2
调整代码大小:
Bitmap tbmp;
//drawing all my features in tbmp with graphics
bmp = new Bitmap(width + 5, height + 5);
bmp.MakeTransparent(Color.Black);
using (var gg = Graphics.FromImage(bmp))
{
gg.CompositingQuality = CompositingQuality.HighQuality;
// gg.SmoothingMode = SmoothingMode.HighQuality;
gg.InterpolationMode = InterpolationMode.HighQualityBicubic;
gg.DrawImage(tbmp, new Rectangle(0, 0, width, height), new Rectangle(GXMin, GYMin, GXMax + 20, GYMax + 20), GraphicsUnit.Pixel);
gg.Dispose();
}
答案 0 :(得分:6)
我使用此方法作为从原始(任何大小)获取缩略图图像(任何大小)的方法。请注意,当您要求的尺寸比率与原始尺寸比率大不相同时,存在固有问题。最好问一下彼此规模的尺寸:
public static Image GetThumbnailImage(Image OriginalImage, Size ThumbSize)
{
Int32 thWidth = ThumbSize.Width;
Int32 thHeight = ThumbSize.Height;
Image i = OriginalImage;
Int32 w = i.Width;
Int32 h = i.Height;
Int32 th = thWidth;
Int32 tw = thWidth;
if (h > w)
{
Double ratio = (Double)w / (Double)h;
th = thHeight < h ? thHeight : h;
tw = thWidth < w ? (Int32)(ratio * thWidth) : w;
}
else
{
Double ratio = (Double)h / (Double)w;
th = thHeight < h ? (Int32)(ratio * thHeight) : h;
tw = thWidth < w ? thWidth : w;
}
Bitmap target = new Bitmap(tw, th);
Graphics g = Graphics.FromImage(target);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
Rectangle rect = new Rectangle(0, 0, tw, th);
g.DrawImage(i, rect, 0, 0, w, h, GraphicsUnit.Pixel);
return (Image)target;
}