我已经意识到我的第一个问题是无法回答的,因为PHP不能处理这种格式:
https://stackoverflow.com/questions/1376103/how-to-convert-metafilepict-to-bitmapped-image-in-php
,所以我有一个C控制台应用程序,它只从MS SQL 2008数据库或Access 2007加载图像,然后将它们保存到一个目录中。
图像最初保存为Windows Media文件(WMF)到Access数据库。
所以,我有以下代码,在最后一行有一个错误:
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);
SQL Server中的“locationmap”列是varbinary,而access中是image。
如何从这两个数据库中的一个中加载它,以便将其保存为位图图像?
这是我的错误:
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);
更新2:我刚刚尝试了这个方法,得到了一个通用的gdi+错误:
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)