public static Image Resize(Image image, Size size)
{
Image bmp = new Bitmap(size.Width, size.Height);
using (var g = Graphics.FromImage(bmp))
{
g.DrawImage(
image,
new Rectangle(0, 0, size.Width, size.Height),
new Rectangle(0, 0, image.Width, image.Height),
GraphicsUnit.Pixel);
}
return bmp;
}
What the code above does is to create a new image with the specified new size and draw the source image to fit the new image.
No comments:
Post a Comment