目前我有第三方控件生成一個圖元文件。我可以將.wmf文件保存到磁盤上,但無法解決問題。問題是如何將Metafile呈現爲Tiff文件。VB.net將MetaFile/EMF保存爲位圖(.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作爲System.IntPtr,BYVAL n大小作爲UInteger,BYVAL的lpData作爲IntPtr的)作爲UInteger 結束函數
<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
我已經嘗試過各種圖像和圖形調用,並且無法將元文件保存爲.tiff文件。任何建議都會很棒。我甚至試圖創建一個新的位圖並將圖元文件繪製到它上面。我總是會拋出一個GDI異常。
這工作,我剛剛與DPI搞砸讓我.TIFF是高質量的。 – pehaada 2010-03-28 16:41:09
元文件是可擴展的。使位圖儘可能大,使用帶有Rectangle的DrawImage重載。 – 2010-03-28 16:54:08