目前我有一个生成元文件的第三方控件。我可以毫无问题地将 .wmf 文件保存到磁盘。问题是如何将 Metafile 呈现为 Tiff 文件。
目前我有以下代码来获取我的元文件并保存它。
Dim mf As Metafile = page.GetImage(TXTextControl.Page.PageContent.All)
Dim enhMetafileHandle As IntPtr = mf.GetHenhmetafile()
Dim h As IntPtr
Dim bufferSize As UInteger = GetEnhMetaFileBits(enhMetafileHandle, 0, h)
Dim buffer(CInt(bufferSize)) As Byte
GetEnhMetaFileBits(enhMetafileHandle, bufferSize, buffer)
Dim msMetafileStream As New MemoryStream
msMetafileStream.Write(buffer, 0, CInt(bufferSize))
Dim baMetafileData() As Byte
baMetafileData = msMetafileStream.ToArray
Dim g As Graphics = Graphics.FromImage(mf)
mf.Dispose()
File.WriteAllBytes("c:\a.wmf", baMetafileData)
结束子
_ 公共共享函数 GetEnhMetaFileBits( ByVal hEMF As System.IntPtr, ByVal nSize As UInteger, ByVal lpData As IntPtr) As UInteger End Function
<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", EntryPoint:="GetEnhMetaFileBits")> _
Public Shared Function GetEnhMetaFileBits(<System.Runtime.InteropServices.InAttribute()> ByVal hEMF As System.IntPtr, ByVal nSize As UInteger, ByVal lpData() As Byte) As UInteger
End Function
我尝试了各种 IMAGE 和 Graphic 调用,但无法将元文件保存为 .tiff。任何建议都会很棒。我什至尝试创建一个新的位图并将元文件绘制到它上面。我总是以抛出 GDI 异常而告终。