2013-08-06 140 views
5

我有一個高質量的圖像(爲了我的需要),我需要調整大小(30 x 30像素),我調整它與graphic.DrawImage。但是,當我調整它變得模糊,輕一點。 我也嘗試過CompositingQuality和InterpolationMode,但它都很糟糕。如何調整圖像的大小而不損失質量

例如,我想要的質量。

我的結果

編輯 圖標我畫我自己的形象,也許這將是更好的繪製小不調整?

EDIT2

Resizeing代碼:

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

縮放圖像,而不是失去的質量=矢量圖形,而不是位圖。 –

+0

您可以向我們展示您正在用於調整大小的*實際代碼嗎? –

+0

添加了實際代碼 – BOBUK

回答

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

嗨,這項工作是否也適用於擴展? –

+0

@ObiOnuorah對於向上擴展超出原始圖像大小,沒有什麼效果......只是沒有可用的圖像信息。 – DonBoitnott

相關問題