2009-11-04 36 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