Bonsoir,
je veux imprimer une image avec le composant SerialPort en vb.net mais ça marche pas . est ce que vous pouvez m'aidez? voici mon code :
La fonction qui convertis l'image en binaire :
La fonction qui imprime l'image :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 Public Function BmpToBytes_MemStream(ByVal bmp As Bitmap) As Byte() Dim ms As New System.IO.MemoryStream() bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) Dim bmpBytes As Byte() = ms.GetBuffer() bmp.Dispose() ms.Close() Return bmpBytes End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Public Sub imprimerImage(ByVal sr As IO.Ports.SerialPort, ByVal img As Drawing.Bitmap) sr .Open() Dim tableau As Byte() = BmpToBytes_MemStream(img) SerialPort1.Write(tableau, 0, tableau.Length - 1) SerialPort1.Write(Chr(Keys.Escape) & "i") SerialPort1.Close() End Sub
Partager