na3er-faraji
چهارشنبه 19 مهر 1391, 18:04 عصر
سلام. من از کد زیر برای کوچک کردن عکس استفاده میکنم. یک قضیه جالبی که پیش میاد اینه که این کد خود به خود میاد کیفیت عکس رو هم کم میکنه و عکس خیلی بی کیفیت میشه. در حالی که من فقط دارم طول و عرض رو کم میکنم. کسی میدونه علت چیه؟
public static void SaveImage(System.Web.HttpPostedFile postedFile, int max, string fileSaveUrl)
{
System.Drawing.Image thumb = System.Drawing.Image.FromStream(postedFile.InputSt ream, true);
int w = thumb.Width;
int h = (max * thumb.Height) / w;
if (h > max)
{
w = (max * thumb.Width) / thumb.Height;
thumb = thumb.GetThumbnailImage(w, max, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
}
else
{
thumb = thumb.GetThumbnailImage(max, h, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
}
thumb.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg,System.Dra wing.Imaging.EncoderParameters.);
}
private static bool ThumbnailCallback()
{
return true;
}
public static void SaveImage(System.Web.HttpPostedFile postedFile, int max, string fileSaveUrl)
{
System.Drawing.Image thumb = System.Drawing.Image.FromStream(postedFile.InputSt ream, true);
int w = thumb.Width;
int h = (max * thumb.Height) / w;
if (h > max)
{
w = (max * thumb.Width) / thumb.Height;
thumb = thumb.GetThumbnailImage(w, max, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
}
else
{
thumb = thumb.GetThumbnailImage(max, h, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
}
thumb.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg,System.Dra wing.Imaging.EncoderParameters.);
}
private static bool ThumbnailCallback()
{
return true;
}