简体   繁体   English

使用内存流以emf格式保存位图

[英]Saving a bitmap in emf format using memory stream


I want to save a bitmap image using memory stream object in emf format. 我想使用emf格式的内存流对象保存位图图像。 When I used save method, it throws following exception: 当我使用save方法时,它抛出以下异常: 在此输入图像描述

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? 请解释一下导致此错误的原因以及如何以emf格式保存文件?

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. 问题是,EMF是图像的矢量类型,PNG,BMP,GIF等是光栅类型

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. 这有助于我使用内存流对象在emf文件中下载图像,但我仍然需要暂时将图像保存在服务器中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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