简体   繁体   中英

Resize Image while maintaining aspect ratio

Hey guys, I have an image that I'm downloading from the internet and need to resize it to 1/4 of it's size while preserving its aspect ratio. Any ideas on how to do this easiest?

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));
}

Thank you!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM