【问题标题】:Converting Metafile image to byte array without System.Drawing在没有 System.Drawing 的情况下将 Metafile 图像转换为字节数组
【发布时间】:2018-02-28 11:38:03
【问题描述】:

我需要在不使用 System.Drawing 的情况下将 wmf 文件转换为字节数组。我不能使用 System.Drawing 的原因是 Azure 环境不支持 GDI+ 的某些功能。该代码将在本地环境中正常执行,但在部署到服务器时将不起作用。为了利用 GDI+,我不得不将我们应用程序之外的调整大小逻辑移动到 Azure VM。我们必须支持遗留应用程序的 wmf 文件。

以下内容在部署到 Azure Web 应用时将失败。

byte[] imgArr;
using (var ms = new MemoryStream())
{
    sourceImage.Save(ms, ImageFormat.Png);
    imgArr = ms.ToArray();
}

var imgCon = new ImageConverter();
var imgArr = (byte[])imgCon.ConvertTo(sourceImage, typeof(byte[]));

两者都使用 System.Drawing 库和使用 GDI+。还有其他方法可以将 Windows 元文件转换为字节数组吗?

【问题讨论】:

    标签: c# asp.net azure system.drawing


    【解决方案1】:

    请尝试使用以下代码,它适用于我。

       FileInfo fileInfo = new FileInfo(path); // the path should be accessed in the azure portal
    
       // The byte[] to save the imgArr in
       byte[] imgArr= new byte[fileInfo.Length];
    
       // Load a filestream and put its content into the byte[]
    
       using (FileStream fs = fileInfo.OpenRead())
       {
           fs.Read(imgArr, 0, imgArr.Length);
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 2013-04-14
      相关资源
      最近更新 更多