繁体   English   中英

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

[英]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.

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