Convertir un WMF en EMF

daveCrocket Messages postés 10 Date d'inscription mercredi 9 janvier 2002 Statut Membre Dernière intervention 30 juillet 2004 - 28 mai 2002 à 15:56
fraisage2003 Messages postés 1 Date d'inscription mercredi 26 février 2003 Statut Membre Dernière intervention 28 mars 2003 - 28 mars 2003 à 15:15
Bonjour à tous,
j'ai récupérer ce source pour transformer un wmf en emf, mais je ne sais pas comment je dois l'utiliser. Pouvez-vous m'aider ?

********************************
Private Const MM_ANISOTROPIC = 8
'...
Private Type SMALL_RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
'...
Private Type METAHEADER
mtType As Integer
mtHeaderSize As Integer
mtVersion As Integer
mtSize As Long
mtNoObjects As Integer
mtMaxRecord As Long
mtNoParameters As Integer
End Type

Private Type APMHEADER
dwKey As Long
hMF As Integer
rcBounds As SMALL_RECT
wInch As Integer
dwReserved As Long
wChecksum As Integer
End Type
Private Const SIZEOF_APMHEADER = 22
Private Const APMHEADER_KEY = &H9AC6CDD7
'...
Private Type METAFILEPICT
mm As Long
xExt As Long
yExt As Long
hMF As Long
End Type
'...
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function SetWinMetaFileBits Lib "gdi32" (ByVal cbBuffer As Long, lpbBuffer As Byte, ByVal hdcRef As Long, lpmfp As METAFILEPICT) As Long
'...
Private Function OpenAPM(ByVal Path As String) As Long ' Returns an EMF handle
On Error GoTo Err_OpenAPM

Dim hEmf As Long
hEmf = 0

Dim hDC As Long
hDC = 0

Dim lBytes As Long, aBytes() As Byte, lBase

' TODO: Read the file into aBytes()
'...
' Open the file for binary access
Dim hFile As Long

Dim Hdra As METAHEADER
Dim mtSize As Long
Dim hMF As Long
hFile = FreeFile
Dim FileName As String
FileName = "c:\carte.wmf"
Open FileName For Binary Access Read As #hFile

' Scan past APMFILEHEADER (22 bytes), and
' grab METAHEADER.
Get #hFile, 23, Hdra

' The size field contains number of WORDs
' in metafile,we need to double for number
' of bytes.
Hdra.mtSize = Hdra.mtSize * 2

' Grab actual metafile data. Need to back
' up to beginning of header.
ReDim aBytes(1 To Hdra.mtSize) As Byte
Get #hFile, 23, aBytes

' Done with file now.
Close hFile

lBase = LBound(aBytes)
lBytes = UBound(aBytes) - LBound(aBytes) + 1

Dim Hdr As APMHEADER
If lBytes >= SIZEOF_APMHEADER Then
CopyMemory Hdr, aBytes(lBase), SIZEOF_APMHEADER
End If
If Hdr.dwKey = APMHEADER_KEY Then
Dim mfp As METAFILEPICT
With mfp
.mm = MM_ANISOTROPIC
.xExt = Hdr.rcBounds.Right - Hdr.rcBounds.Left
If .xExt < 0 Then .xExt = -1 * .xExt
.xExt = (2540 / Hdr.wInch) * .xExt

.yExt = Hdr.rcBounds.Bottom - Hdr.rcBounds.Top
If .yExt < 0 Then .yExt = -1 * .yExt
.yExt = (2540 / Hdr.wInch) * .yExt
End With

hDC = GetDC(0)
If 0 <> hDC Then
hEmf = SetWinMetaFileBits(lBytes - SIZEOF_APMHEADER, aBytes(lBase + SIZEOF_APMHEADER), hDC, mfp)
End If
End If

OpenAPM = hEmf
GoTo Exit_OpenAPM

Err_OpenAPM:
GoTo Exit_OpenAPM

Exit_OpenAPM:
If (0 <> hDC) Then
ReleaseDC 0, hDC
End If
End Function

3 réponses

VicoLaChips2 Messages postés 436 Date d'inscription dimanche 20 janvier 2002 Statut Membre Dernière intervention 2 février 2010 2
28 mai 2002 à 16:26
Salut.
Open "toto.wmf" For Binary As #1
Write #1, OpenAPM(CheminVersMonFichierEmf)

ça marche ??

@+
0
daveCrocket Messages postés 10 Date d'inscription mercredi 9 janvier 2002 Statut Membre Dernière intervention 30 juillet 2004
28 mai 2002 à 16:55
salut,
tu as réussi à le faire fonctionner ?
j'ai pas bien compris ta réponse.
0
fraisage2003 Messages postés 1 Date d'inscription mercredi 26 février 2003 Statut Membre Dernière intervention 28 mars 2003
28 mars 2003 à 15:15
fraisage2003
j'aimerais savoir comment convertir un fichier WMF en EMF et pour convertir un fichier DXF en WMf ( voir en EMF )
merci d'avance
0
Rejoignez-nous