如何在不损失质量的情况下调整图像大小 [英] How resize image without losing quality

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

问题描述

我有一个质量好的大图像(满足我的需要),我需要调整到小尺寸(30 x 30px),我用graphic.DrawImage调整它的大小.但是当我调整大小时,它变得模糊并且变轻了.我也尝试过 CompositingQuality 和 InterpolationMode,但都不好.

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.

我的结果

已编辑我自己画的图标图像,也许不调整大小就画小一点会更好?

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

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

推荐答案

我使用此方法作为从原始(任何大小)获取缩略图(任何大小)的一种方式.请注意,当您要求与原始尺寸比例差异很大的尺寸比例时,存在固有问题.最好询问彼此成比例的尺寸:

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天全站免登陆