【问题标题】:How resize image without losing quality如何在不损失质量的情况下调整图像大小
【发布时间】:2013-08-06 15:28:33
【问题描述】:

我有一个质量很好的大图像(满足我的需要),我需要将其调整为小尺寸(30 x 30 像素),我使用graphic.DrawImage 调整它的大小。但是当我调整大小时,它会变得模糊且更轻。 我也尝试过 CompositingQuality 和 InterpolationMode,但这一切都很糟糕。

例如,我正在努力获得的品质。

我的结果

已编辑 我自己画的图标的图像,不调整大小可能会更好吗?

编辑2

调整代码大小:

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

【问题讨论】:

  • 缩放图像,不损失质量 = 矢量图形,而不是位图。
  • 您能否向我们展示您用于调整大小的实际代码

标签: c# graphics


【解决方案1】:

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

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

【讨论】:

  • @ObiOnuorah 没有什么能很好地放大原始图像大小......只是没有可用的图像信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
  • 1970-01-01
相关资源
最近更新 更多