【问题标题】:Saving a bitmap in emf format using memory stream使用内存流以 emf 格式保存位图
【发布时间】:2013-06-04 16:45:55
【问题描述】:


我想使用内存流对象以 emf 格式保存位图图像。当我使用保存方法时,它会抛出以下异常:

代码:

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

        image.Save(stream, ImageFormat.Emf);

请解释一下导致此错误的原因以及如何将文件保存为 emf 格式?

感谢和问候,
阿南德

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    问题是,EMF 是 vector 类型的图像,而 PNG、BMP、GIF 等是光栅

    除非您为此使用一些额外指定的软件,否则不能简单地将光栅转换为矢量。

    【讨论】:

    • 是否可以使用c#将位图中的png文件转换为emf格式?
    • 是的,如果您创建自己的转换器。 Wiki.
    【解决方案2】:

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

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

    这帮助我使用内存流对象将图像下载到 emf 文件中,但我仍然必须将图像临时保存在服务器中。

    谢谢大家的回复。

    【讨论】:

      【解决方案3】:
      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);*/
      

      【讨论】:

      • 另外,在代码中添加一些解释以向 OP 展示导致错误、错误的原因总是很好的......
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 2010-11-23
      • 2021-10-06
      相关资源
      最近更新 更多