如何调整图像不失去质量 [英] How resize image without losing quality

查看:156
本文介绍了如何调整图像不失去质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有良好的质量大图像(我需要),我需要调整到小尺寸(30×30像素),我graphic.DrawImage调整其大小。但是,当我调整它的大小变得模糊,有点轻。
我也有尝试CompositingQuality和InterpolationMode,但是这一切是坏的。



例如,质量我想要得到什么。





我的结果





编辑图标的
图片我画我自己,也许这将是更好地绘制小没有调整?



EDIT2



Resizeing代码:

 位图TBMP; 
//画我的TBMP所有功能与图形
BMP =新位图(宽+ 5,高度+ 5);
bmp.MakeTransparent(Color.Black);使用
(VAR GG = Graphics.FromImage(BMP))
{
gg.CompositingQuality = CompositingQuality.HighQuality;
// gg.Smoothi​​ngMode = Smoothi​​ngMode.HighQuality;
gg.InterpolationMode = InterpolationMode.HighQualityBicubic;

gg.DrawImage(TBMP,新的Rectangle(0,0,宽度,高度),新的Rectangle(GXMin,GYMin,GXMax + 20,+ GYMax 20),GraphicsUnit.Pixel);
gg.Dispose();
}


解决方案

我用这个方法作为方式从(任意大小的)的原始得到(任意大小的)的缩略图图像。请注意,有固有的问题时,要求的尺寸比从原始的变化很大。最好问一下对于那些规模到另一个尺寸:

 公共静态图像GetThumbnailImage(图片OriginalImage,大小ThumbSize)
{
的Int32 thWidth = ThumbSize.Width;
的Int32 thHeight = ThumbSize.Height;
图像I = OriginalImage;
的Int32 W = i.Width;
的Int32 H = i.Height;
的Int32日= thWidth;
的Int32 TW = thWidth;
如果(H> W)
{
双率=(双人间)W /(双人间)H;
TH = thHeight< H ? thHeight:H;
TW = thWidth< W' (Int32)已(比* thWidth):W;
}
,否则
{
双率=(双人间)H /(双人间)瓦;
TH = thHeight< H ? (Int32)已(比* thHeight):H;
TW = thWidth< W' thWidth:W;
}
位图的目标=新位图(TW,TH);
图形G = Graphics.FromImage(目标);
g.Smoothi​​ngMode = Smoothi​​ngMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
矩形RECT =新的Rectangle(0,0,TW,TH);
g.DrawImage(ⅰ,矩形,0,0,W,H,GraphicsUnit.Pixel);
返回(图像)的目标;
}


I have a big image in good quality (for my needs), i need resize to small size (30 x 30px), I resize it with graphic.DrawImage. But when i resize it become blurred and little lighter. also I have try CompositingQuality and InterpolationMode, but it all was bad.

Example, that quality i'm trying get.

My result

Edited Image of icon i draw myself, maybe it will be better draw it small without resizing?

Edit2

Resizeing code:

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

解决方案

I use this method as a way to get a thumbnail image (of any size) from an original (of any size). Note that there are inherent issues when you ask for a size ratio that varies greatly from that of the original. Best to ask for sizes that are in scale to one another:

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

这篇关于如何调整图像不失去质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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