简体   繁体   中英

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: 在此输入图像描述

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

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.

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.

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);*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM