2013-05-13 200 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