Try
Dim CD As New WIA.CommonDialog
Dim F As WIA.ImageFile = CD.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MinimizeSize, , True, True)
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)
'Write Bytes To Local Disk
File.WriteAllBytes("d:\test.jpg", MStream.ToArray)
Catch ex As Exception
MsgBox("ผิดพลาด : " & ex.Message)
End Try
If MStream IsNot Nothing Then MStream.Dispose()
End If
Catch ex As Exception
Select Case _WiaErrCode(ex.Message)
Case "0x80210015" '// No device detected.
msgStr = "ไม่พบอุปกรณ์สำหรับสแกนรูปภาพ "
msgStr &= "ตรวจสอบให้แน่ใจว่าอุปกรณ์สแกน ได้ติดตั้งแล้ว เสียบสายต่อเข้าคอมพิวเตอร์และเปิดอุปกรณ์สแกนแล้ว"
MessageBox.Show(Me, msgStr, "ไม่พบอุปกรณ์", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Case "0x80210064" '// Cancel was pressed
Case Else
MessageBox.Show(Me, "Error: " & ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Select
End Try