Hi @STL ,
You can consider saving Metafile as EMF, and then reload it.
Here's an example you can refer to.
<DllImport("gdi32.dll")>
Private Shared Function CopyEnhMetaFile(ByVal hemfSrc As IntPtr, ByVal lpszFile As String) As IntPtr
End Function
<DllImport("gdi32.dll")>
Private Shared Sub DeleteEnhMetaFile(ByVal hemf As IntPtr)
End Sub
Public Function ReloadMetaFile(ByVal mf As Metafile, ByVal fileName As String) As Metafile
Dim iptrMetafileHandle As IntPtr = mf.GetHenhmetafile()
CopyEnhMetaFile(iptrMetafileHandle, fileName)
DeleteEnhMetaFile(iptrMetafileHandle)
Dim bm As Bitmap = New Bitmap(16, 16)
Using gr As Graphics = Graphics.FromImage(bm)
mf = New Metafile(fileName, gr.GetHdc())
gr.ReleaseHdc()
End Using
Return mf
End Function
Use it:
Dim myImage As Metafile = ...
Dim mf As Metafile = ReloadMetaFile(myImage, "EMF file path")
Dim gr As Graphics = Graphics.FromImage(mf)
...
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.