I used multi file upload to upload file in ASP.Net without issues. But now i want to add more functionality like creating thumbnails while uploading below is my code:
try
{
string _path = "~/photos/realimg/";
string _thumPath = "~/photos/thumbimg/";
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
_path += System.IO.Path.GetFileName(hpf.FileName);
_thumPath += System.IO.Path.GetFileName(hpf.FileName.Insert(0, "thumb_"));
hpf.SaveAs(Server.MapPath(_path));
SavePicPath(_path);
System.Drawing.Image realImg = System.Drawing.Image.FromFile(Server.MapPath(_path));
Int32 rH = realImg.Height;
Int32 rW = realImg.Width;
Int32 fW = 170;
Int32 fH = (Int32)Math.Floor((double)rH * (fW / rW));
System.Drawing.Image thumbimg = realImg.GetThumbnailImage(fW, fH, null, IntPtr.Zero);
thumbimg.Save(Server.MapPath(_thumPath));
SavePicPath(_thumPath);
}
}
}
catch
{
}
Anytime it gets to GetThumbnailImage i get an error “Out of memory” please any correction or what am i doing wrong
Change int values to (float or double). i think here
fw/rwreturning int value than float or double value.