2009-11-04 39 views
0

我想縮放圖像,這些天,找到下面的例子:兩塊代碼約縮放圖像

例子#1的 http://www.codeproject.com/KB/GDI-plus/imageresize.aspx

幾個測試後,我寫了下面的代碼:

static System.Drawing.Image Scale(System.Drawing.Image imgPhoto, int v_iPercent) 
{ 
    int destWidth = (int)(imgPhoto.Width * v_iPercent/100.0); 
    int destHeight = (int)(imgPhoto.Height * v_iPercent/100.0); 
    Bitmap bmPhoto = new Bitmap(imgPhoto, destWidth, destHeight); 
    return bmPhoto; 
} 

我想知道爲什麼我找到的例子需要使用Graphics.DrawImage函數來縮放圖像。

回答

1

你見過什麼是Bitmap constructor您使用DO:

public Bitmap(Image original, int width, int height) : this(width, height) 
{ 
    using (Graphics graphics = null) 
    { 
     graphics = Graphics.FromImage(this); 
     graphics.Clear(Color.Transparent); 
     graphics.DrawImage(original, 0, 0, width, height); 
    } 
} 

它調用DrawImage

+0

你在哪裏找到位圖構造函數的代碼? – Billy 2009-11-04 08:07:39

+0

紅門的.NET反射器(http://www.red-gate.com/products/reflector/) – 2009-11-04 08:18:56