2009-10-10 97 views
0

我已经意识到,我的第一个问题不会回答的,因为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) 
+0

你可以在图像查看器中打开tempfile.wmf吗?听起来像原始文件或存储方式可能有问题? – 2009-10-10 13:24:51

+0

我确实试图打开它,但它确实有错误,所以我需要发送更多文件并查看第一个文件是否有一些不良信息。 – 2009-10-10 15:16:17

回答

1

您可能会发现在斯蒂芬Lebans'样本数据库的代码照明:

这不是专门针对WMF - 它可以用于任何OLE领域。我在4个月前使用它从客户端数据库中提取了一堆Word文档,并且它工作正常(尽管只有少数填充了旧版Word的字段无法提取)。

+0

+1 - 用于一个有用的工具。它告诉我数据有问题,因为在49个字段中,有1个被提取,然后出现错误。所以,问题不在于我的方法,有一些Access可以做,我做不到,看来。 – 2009-10-11 01:55:39