2013-05-13 198 views
0


我想使用emf格式的内存流对象保存位图图像。当我使用的保存方法,它抛出以下异常:enter image description here使用内存流保存位图格式为emf格式

代码:

 Bitmap image = new Bitmap(Server.MapPath("Stacking.Png")); 
     MemoryStream stream = new MemoryStream(); 

     image.Save(stream, ImageFormat.Emf); 

请给我解释一下是什么原因造成这个错误,我怎么能保存在EMF格式文件?

感谢和问候,
阿南德

回答

1

我找到了一个简单的解决方法。我用下面的代码:

 image.Save(Server.MapPath(FileName)); 
     MemoryStream stream1 = new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath(Filename))); 
     System.IO.File.Delete(Server.MapPath(Filename)); 

帮我用内存流对象下载图像中的EMF文件,但仍然我不得不暂时保存图像的服务器。

感谢您的回复家伙。

1

的事情是,在EMF是一个vector类型的图像,以及PNG,BMP,GIF等都是光栅的。

一个不能简单地将栅格转换为矢量,除非你使用一些额外的指定软件。

+0

是否有可能使用c#将位图中的png文件转换为emf格式? – Anandaraj 2013-05-13 11:51:10

+0

是的,如果你创建你自己的转换器。 [维基](http://en.wikipedia.org/wiki/Vectorization_(image_tracing))。 – AgentFire 2013-05-13 12:15:14

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

请在发布之前预览您的回答 - 至少应用基本格式... – 2013-05-27 08:29:08

+0

此外,在代码中添加一些解释以显示OP是什么导致错误,错误,.... – Mahm00d 2013-05-27 08:49:08