1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonScan.Click
Dim CD As New WIA.CommonDialog
Dim F As WIA.ImageFile = CD.ShowAcquireImag(WIA.WiaDeviceType.ScannerDeviceType)
If F IsNot Nothing Then
Dim MStream As IO.MemoryStream = Nothing
Try
'Convert the raw scanner output into a byte array
Dim ImgBytes() As Byte = DirectCast(F.FileData.BinaryData, Byte())
'Read the image data bytes into a MemoryStream
MStream = New IO.MemoryStream(ImgBytes)
'Create a Bitmap from the memory stream data
Dim Bmp As New Drawing.Bitmap(MStream)
'Assign the bitmap as the PictureBox Image
If FormatType = "image" Then
Dim nameNB As Integer
Bmp.Save("D:\Numérisations\" & NameDoc & nameNB + 1 & Format, imgFormat)
PictureBox1.Image = Bmp
'Do a victory dance. It worked!
Else
MsgBox("fonction non disponible pour le momment", vbOKOnly, Title:="erreur")
End If
Catch ex As Exception
MsgBox("une erreur s'est produite pendant la conversion scan données a la création du fichier: " & ex.Message)
End Try
If MStream IsNot Nothing Then MStream.Dispose()
End If
Return
End Sub |
Partager