在保持纵横比的同时调整图像大小

时间:2011-05-09 21:45:42

标签: c#

嘿伙计们,我有一张图片,我正在从互联网上下载,需要将其大小调整为1/4,同时保留其宽高比。关于如何做到这一点最简单的任何想法?

WebRequest requestPic = WebRequest.Create(imageURL);
WebResponse responsePic = requestPic.GetResponse();
Image webImage = Image.FromStream(responsePic.GetResponseStream());

// Need to resize image here

Random rand = new Random();
string imageName = string.Format("{0:x}{1:x}", DateTime.Now.Ticks, rand.Next(0, 60400000));
if (webImage != null)
{
     webImage.Save(string.Format("c:\\{0}.jpg", imageName));
}

谢谢!

1 个答案:

答案 0 :(得分:4)

Image thumb = image.GetThumbnailImage(image.Width / 2, image.Height / 2, null, IntPtr.Zero);
image.Dispose();