I want to convert the image to base64 and go back to the image again. Here is the code I've tried so far and the error. Any suggestions please?
public void Base64ToImage(string coded) { System.Drawing.Image finalImage; MemoryStream ms = new MemoryStream(); byte[] imageBytes = Convert.FromBase64String(coded); ms.Read(imageBytes, 0, imageBytes.Length); ms.Seek(0, SeekOrigin.Begin); finalImage = System.Drawing.Image.FromStream(ms); Response.ContentType = "image/jpeg"; Response.AppendHeader("Content-Disposition", "attachment; filename=LeftCorner.jpg"); finalImage.Save(Response.OutputStream, ImageFormat.Jpeg); }
Mistake:
The parameter is not valid.
Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.
Exception Details: System.ArgumentException: The parameter is not valid.
Source Error:
Line 34: ms.Read(imageBytes, 0, imageBytes.Length); Line 35: ms.Seek(0, SeekOrigin.Begin); Line 36: finalImage = System.Drawing.Image.FromStream(ms); Line 37: Line 38: Response.ContentType = "image/jpeg";
Source file: e: \ Practical projects \ FaceDetection \ Default.aspx.cs Line: 36
Chandra eskay
source share