我已经意识到,我的第一个问题不会回答的,因为PHP不能用这种格式处理:https://stackoverflow.com/questions/1376103/how-to-convert-metafilepict-to-bitmapped-image-in-php,所以我有一个C#控制台应用程序将只加载了来自MS SQL 2008 db或Access 2007的图像,然后将它们保存到目录中。阅读从数据库WMF文件,转换成位图图像
图像最初保存为访问数据库的Windows Media文件(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);
SQL Server中的列“LocationMap”是VARBINARY,并在访问是形象。
如何从两个数据库之一加载这个,所以我可以将其保存为位图图像?
这是我的错误:
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)
UPDATE:这是我的另一个失败的尝试:
//imageBytes = sdr.GetSqlBytes(2);
//var stream = imageBytes.Stream;
//stream.Seek(0, SeekOrigin.Begin);
//locmod.LocationImage = new Metafile(stream);
UPDATE2:我只是尝试这样做,有一个通用的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)
你可以在图像查看器中打开tempfile.wmf吗?听起来像原始文件或存储方式可能有问题? – 2009-10-10 13:24:51
我确实试图打开它,但它确实有错误,所以我需要发送更多文件并查看第一个文件是否有一些不良信息。 – 2009-10-10 15:16:17