int newWidth = 100;
int newHeight = 100;
double ratio = 0;
if (img1.Width > img1.Height)
{
ratio = img1.Width/img1.Height;
newHeight = (int)(newHeight/ratio);
}
else
{
ratio = img1.Height/img1.Width;
newWidth = (int)(newWidth/ratio);
}
Image bmp1 = img1.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
bmp1.Save(Server.MapPath("~/Uploads/Photos/Thumbnails/") + photo.PhotoID + ".jpg");
我总是用高度和宽度为相同的值(100)
我obiously做错事与类型转换的图像?C#新手问题变量类型
你得到了什么错误? – 2010-03-26 15:25:41
'img1.Width'和'img1.Height'有什么值? – 2010-03-26 15:27:12
@Präriewolf:我没有得到任何错误。 @PéterTörök:嗯...我不太确定,但我认为它是整数,因为我可以声明newWidth = img1.Width而没有错误。 – 2010-03-26 15:30:41