VB.net Saving an MetaFile / EMF as a bitmap ( .tiff)
Posted
by pehaada
on Stack Overflow
See other posts from Stack Overflow
or by pehaada
Published on 2010-03-24T22:07:13Z
Indexed on
2010/03/25
1:33 UTC
Read the original article
Hit count: 432
Currently I have a third party control that generates a Metafile. I can save the .wmf file to disk with out issue. The problem is how do I render the Metafile as a Tiff file.
Currently I have the following code to get my metafile and save it.
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)
end sub
_ Public Shared Function 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
I've tried all sort of IMAGE and Graphic calls and just can't save the meta file as a .tiff. Any suggestions would be great. I even tried to create a new bitmap and draw the metafile onto it. I always end up with a GDI exception being thrown.
© Stack Overflow or respective owner