2009-12-12 49 views
1

我有交流#-class看起來大致是這樣的:調整大小在C#中的圖像,而不會丟失低的右像素部分

class ImageContainer 
{ 
    Image image; 
    internal ImageContainer getResized(int width, int height) 
    { 
    Bitmap bmp = new Bitmap(width, height); 
    //Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the high quality scaled image 
    System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
    //Set the System.Drawing.Graphics object property SmoothingMode to HighQuality 
    gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
    //Set the System.Drawing.Graphics object property CompositingQuality to HighQuality 
    gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
    //Set the System.Drawing.Graphics object property InterpolationMode to High 
    gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
    //Draw the original image into the target Graphics object scaling to the desired width and height 
    System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, width, height); 
    gr.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); 
    //dispose/release resources 

    ImageContainer ic = new ImageContainer(); 
    ic.image = bmp; 

    return ic; 
    } 
} 

的大小調整工作正常,但的DrawImage不畫最正確的縮小圖像時降低像素片段。

回答

3

問題是由

gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; 

:)

+0

PixelOffsetMode.Half也適用解決。 – Pedro77 2013-12-25 21:14:49

相關問題