Home > Net >  About vector diagram by CopyEnhMetaFile saved file being used
About vector diagram by CopyEnhMetaFile saved file being used

Time:11-09

'here I cite a simple reading emf files as an example, the practical application is other metafile
Dim metafile As New metafile (" D: \ 12345. Emf ")
I use the following line of code to save out of emf file cannot be loaded into the visio, the prompt "failed to import graphics file", shall not be deprecated
Metafile. Save (" D: \ \ 11111. Emf, "ImageFormat. Emf)
After using the following function (SaveEnhMetafileToFile) save the file can be visio loading, and "curve combination", this is what I need,
'but the problem is that must be closed after the exe to delete file, the file has been used, and a great god help look at the problem in where?
 Imports System. Drawing. Imaging 
Imports System. The Runtime. InteropServices
Imports System. Text
Private Shared Function OpenClipboard (hWndNewOwner As IntPtr) As Boolean
End the Function
Private Shared Function EmptyClipboard () As a Boolean
End the Function
Private Shared Function SetClipboardData (uFormat As UInteger hMem As IntPtr) As IntPtr
End the Function
Private Shared Function CloseClipboard () As a Boolean
End the Function
Private Shared Function CopyEnhMetaFile (hemfSrc As IntPtr, hNULL As System. Text. StringBuilder) As IntPtr
End the Function
Private Shared Function CloseEnhMetaFile (HDC As IntPtr) As an Integer
End the Function
Private Shared Function DeleteEnhMetaFile (hemf As IntPtr) As IntPtr
End the Function
The Public Function SaveEnhMetafileToFile (mf As Metafile, fileName As String) As Boolean
Dim bResult As Boolean=False
Dim hEMF As IntPtr
Try
HEMF=mf. GetHenhmetafile ()
If Not hEMF. Equals (New IntPtr (0)) Then
Dim tempName As New StringBuilder (fileName)
CopyEnhMetaFile (hEMF tempName)
CloseEnhMetaFile (hEMF) '=====useless, or occupied
DeleteEnhMetaFile (hEMF) '=====or useless, or occupied
Mf. The Dispose () '=====still useless, or occupied, collapsed
End the If
Catch the ex As Exception
Return False
End the Try

Return bResult
End the Function

Private Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
'here I cite a simple reading emf files as an example, the practical application is other metafile
Dim metafile As New metafile (" D: \ 12345. Emf ")
'I use the following line of code to save out of emf file cannot be loaded into the visio, the prompt "failed to import graphics file", not deprecated
'the metafile. Save (" D: \ \ 11111. Emf, "ImageFormat. Emf)
'to save the file after the following functions can be visio loading, and "curve combination", this is what I need,
'but the problem is that must be closed after the exe to delete file, the file has been holding the
SaveEnhMetafileToFile (metafile, "D: \ \ 22222. Emf")
End Sub

CodePudding user response:

Find the reason, you need to remove CopyEnhMetaFile handle to create,
 Friend Shared Function SaveEnhMetafileToFile (mf As Metafile, fileName As String) As Boolean 
Dim bResult As Boolean=False
Dim hEMF As IntPtr
HEMF=mf. GetHenhmetafile ()
'invalidates mf
If Not hEMF. Equals (New IntPtr (0)) Then
Dim tempName As New StringBuilder (fileName)
Dim hCopyEMF As IntPtr=CopyEnhMetaFile (hEMF tempName. ToString ())
DeleteEnhMetaFile (hCopyEMF)
DeleteEnhMetaFile (hEMF)
End the If
Return bResult
End the Function
  • Related