调整图像大小,同时保持纵横比
本文关键字:图像 调整 | 更新日期: 2023-09-27 17:55:57
嘿伙计们,我有一张从互联网上下载的图像,需要将其大小调整为大小的 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));
}
谢谢!
Image thumb = image.GetThumbnailImage(image.Width / 2, image.Height / 2, null, IntPtr.Zero);
image.Dispose();