Anandaraj
Anandaraj

Reputation: 161

Saving a bitmap in emf format using memory stream


I want to save a bitmap image using memory stream object in emf format. When I used save method, it throws following exception:enter image description here

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

Answers (3)

Anandaraj
Anandaraj

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

navjyot verma
navjyot verma

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

AgentFire
AgentFire

Reputation: 9780

The thing is, the EMF is a vector type of an image, and PNG, BMP, GIF etc are the raster ones.

One cannot simply convert raster into the vector unless you are using some extra specified software for this.

Upvotes: 1

Related Questions