代码之家  ›  专栏  ›  技术社区  ›  James Black

从数据库读取WMF文件,转换为位图图像

  •  0
  • James Black  · 技术社区  · 16 年前

    https://stackoverflow.com/questions/1376103/how-to-convert-metafilepict-to-bitmapped-image-in-php

    最初,这些图像作为Windows Media File(WMF)保存到访问数据库中。

    所以,我有以下代码,最后一行有一个错误:

    byte[] mybytes = (byte[])sdr["LocationMap"];
    System.IO.MemoryStream ms =
           new System.IO.MemoryStream(mybytes);
    System.Drawing.Bitmap b =
      (System.Drawing.Bitmap)System.Drawing.Image.FromStream(ms);                        
    

    我如何从这两个数据库中的一个加载它,以便将其另存为位图图像?

    A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll
    System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>ConvertWMFToFile.vshost.exe</AppDomain><Exception><ExceptionType>System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Parameter is not valid.</Message><StackTrace>   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
       at System.Drawing.Image.FromStream(Stream stream)
    

    //imageBytes = sdr.GetSqlBytes(2);
    //var stream = imageBytes.Stream;
    //stream.Seek(0, SeekOrigin.Begin);
    //locmod.LocationImage = new Metafile(stream);
    

    byte[] mybytes = (byte[])sdr["LocationMap"];
    var f = File.Create("tempfile.wmf");
    f.Write(mybytes, 0, locmod.LocationImageBytes.Length);
    f.Close();
    var myimage = new Metafile("tempfile.wmf");
    

    System.Runtime.InteropServices.ExternalException was unhandled
      Message="A generic error occurred in GDI+."
      Source="System.Drawing"
      ErrorCode=-2147467259
      StackTrace:
           at System.Drawing.Imaging.Metafile..ctor(String filename)
    
    2 回复  |  直到 9 年前
        1
  •  1
  •   David-W-Fenton    16 年前

    您可能会发现Stephen Lebans的示例数据库中的代码很有启发性:

        2
  •  1
  •   Brian ONeil    16 年前
    推荐文章