Reputation: 161
I want to save a bitmap image using memory stream object in emf format. When I used save method, it throws following exception:
Code:
Bitmap image = new Bitmap(Server.MapPath("Stacking.Png"));
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Emf);
Please explain me what is causing this error and how can I save the file in emf format?
Thanks and regards,
Anand
Upvotes: 1
Views: 2836
Reputation: 161
I found a simple workaround for this. I used the following code:
image.Save(Server.MapPath(FileName));
MemoryStream stream1 = new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath(Filename)));
System.IO.File.Delete(Server.MapPath(Filename));
This helped me downloading the image in emf file using memory stream object but still I have to save the image temporarily in server.
Thanks for the reply guys.
Upvotes: 1
Reputation: 19
string image = Convert.ToBase64String(System.IO.File.ReadAllBytes("c:\\1.43-Branches-and-Birds.png"));
byte[] encodedDataAsBytes = Convert.FromBase64String(image);
Stream ImageStream = new MemoryStream(encodedDataAsBytes);
string UniqueFileName = Guid.NewGuid().ToString("n") + ".bmp";
string UniqueFileName = userregistration.Id + "_abcd.png";
string uploadFolderPath = "~/ProfileImage/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
System.Drawing.Image img = System.Drawing.Image.FromStream(ImageStream);
img.Save(HttpContext.Current.Request.PhysicalApplicationPath + "ProfileImage\\" + UniqueFileName, System.Drawing.Imaging.ImageFormat.Emf);*/
Upvotes: -1