[英]Saving a bitmap in emf format using memory stream
我想使用emf格式的內存流對象保存位圖圖像。 當我使用save方法時,它拋出以下異常:
碼:
Bitmap image = new Bitmap(Server.MapPath("Stacking.Png"));
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Emf);
請解釋一下導致此錯誤的原因以及如何以emf格式保存文件?
謝謝並恭祝安康,
阿南德
問題是,EMF是圖像的矢量類型,PNG,BMP,GIF等是光柵類型 。
除非您使用一些額外的指定軟件,否則不能簡單地將柵格轉換為矢量。
我找到了一個簡單的解決方法。 我使用了以下代碼:
image.Save(Server.MapPath(FileName));
MemoryStream stream1 = new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath(Filename)));
System.IO.File.Delete(Server.MapPath(Filename));
這有助於我使用內存流對象在emf文件中下載圖像,但我仍然需要暫時將圖像保存在服務器中。
謝謝你的回復。
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.