Extraire l'image .JPEG encapuslée dans une pièce .CATPart (CATIA V5)

  • Initiateur de la discussion Membre supprimé 203959
  • Date de début
M

Membre supprimé 203959

Guest
Bonjour,

Je suis débutant dans la programmation en langage VBA sous Excel.

Pourriez-vous m'aider à concevoir le programme ci-dessous, s'il vous plaît.

Merci d'avance pour votre aide.

PS : Impossible d'utiliser le logiciel CATIA V5, CATDMUUtility Batch Process et autres logiciels (visionneuse/conversion) en .exe => Je peux seulement coder en VBA sous Excel ;)


Langage de programmation en VBA sous Excel

Objectif : Extraire l'image .JPEG encapuslée dans une pièce .CATPart (CATIA V5).

01.JPG

02.JPG

STRUCTURE DU PROGRAMME

'Debut
Sub CATPART2JPEG()

1 - Déclaration et initialisation des variables.
Dim truc As Byte, etc...

2 - Ouvrir le fichier CATPart en lecture en mode binaire.
Open ".CATpart" For Binary As #1

'BOUCLE
While Not EOF(#1)

3 - Lire le fichier CATPart
Get #1, Position , Input ?

4 - Enregistrer dans un tableau temporaire le début du JPEG (0xFFD8) jusqu'à la fin du JPEG (0xFFD9)
?

'FIN DE BOUCLE
Wend

5 - Fermer le fichier CATPArt
Close #1

6 - Créer un fichier JPEG avec les valeurs du tableau temporaire
?

'Fin
End sub
 

Pièces jointes

  • 01.JPG
    01.JPG
    12.9 KB · Affichages: 48
  • 02.JPG
    02.JPG
    13.1 KB · Affichages: 38
M

Membre supprimé 203959

Guest
Re : Extraire l'image .JPEG encapuslée dans une pièce .CATPart (CATIA V5)

Bonjour,

Pourriez-vous m'aider à transposer ce code VB en VBA, svp.

Merci.

Code:
Public Function GetImageFromCatiaFile(infile As String) As Image
Try
Dim xByte As Byte
Dim bPicEnd As Boolean
Dim fs_in As New FileStream(infile, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs_in)
Dim fs_out As New MemoryStream()
Dim bw As New BinaryWriter(fs_out)
While Not (br.BaseStream.Position = br.BaseStream.Length) And Not bPicEnd
xByte = br.ReadByte
If xByte = 255 Then ' FF
xByte = br.ReadByte
If xByte = 216 Then ' D8
xByte = br.ReadByte
If xByte = 255 Then ' FF
bw.Write(CType(255, Byte))
bw.Write(CType(216, Byte))
bw.Write(CType(255, Byte))
While Not (br.BaseStream.Position = br.BaseStream.Length)
xByte = br.ReadByte
bw.Write(CType(xbyte, Byte))
If xByte = 255 Then ' FF
xByte = br.ReadByte
If xByte = 217 Then ' D9
bw.Write(CType(xbyte, Byte))
bPicEnd = True
Else
bw.Write(CType(xbyte, Byte))
End If
End If
End While
End If
End If
End If
End While
Dim img As Image = Image.FromStream(fs_out)
br.Close()
bw.Close()
fs_in.Close()
fs_out.Close()
Return img
Catch
Return Nothing
End Try
End Function
 

Discussions similaires

Réponses
2
Affichages
925

Statistiques des forums

Discussions
314 208
Messages
2 107 290
Membres
109 796
dernier inscrit
aelgar