i have written a code for resizing the images and its working good except for some images that too the issue is occuring only on locolhost(IIS). I have asynchronous file upload contorl and two button controls. when clicked on first button the asynchronous
file upload control is saved in session using the following code
Remove the following two lines of code and it should work. Remember that Image.FromStream() needs a stream that has been Seek()'d to byte 0, or hasn't been read from.
praveen.k
Member
127 Points
209 Posts
Parameter is not valid exception on image.fromstream() method
Apr 07, 2011 03:46 PM|LINK
Hi,
i have written a code for resizing the images and its working good except for some images that too the issue is occuring only on locolhost(IIS). I have asynchronous file upload contorl and two button controls. when clicked on first button the asynchronous file upload control is saved in session using the following code
Session["myupload"] = AsyncFileUpload1.PostedFile;
The image is resized and saved in a folder when second button clicked. The following code will execute when clicked the second button.
HttpPostedFile hif = (HttpPostedFile)Session["myupload"] if (hif.ContentLength <= 20000000) { if (checkfiletype(hif.FileName)) { string spacefileName = hif.FileName; string storePath = Server.MapPath("~") + "/Docs"; //MemoryStream source = hif.InputStream; Stream source = hif.InputStream; //source =(MemoryStream)hif.InputStream; byte[] input=new byte[hif.ContentLength]; source.Read(input, 0, hif.ContentLength); string dest = Server.MapPath("~/Docs/" + fileName); Imageresize(dest, source); //calling imageresize method private void Imageresize(string dest, Stream src) { System.Drawing.Image img = System.Drawing.Image.FromStream(src); int srcWidth = img.Width; int srcHeight = img.Height; int _thumbnailSize = 620; int width, height; if (img.Width > img.Height) { width = _thumbnailSize; height = img.Height * _thumbnailSize / img.Width; } else { width = img.Width * _thumbnailSize / img.Height; height = _thumbnailSize; } Bitmap target = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(target); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.High; Rectangle rectDestination = new Rectangle(0, 0, width, height); graphics.DrawImage(img, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); target.Save(dest); target.Dispose(); img.Dispose(); }Could any one help me why the issue is getting on Localhost only.
Thanks
nathanael.jo...
Member
137 Points
37 Posts
Re: Parameter is not valid exception on image.fromstream() method
May 03, 2011 06:24 PM|LINK
Remove the following two lines of code and it should work. Remember that Image.FromStream() needs a stream that has been Seek()'d to byte 0, or hasn't been read from.