这是一些代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CD As New WIA.CommonDialog
Dim F As WIA.ImageFile = CD.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType)
F.SaveFile("C:\Temp\WIA.jpg")
End Sub
通过这个我可以用WIA扫描照片(Windows Image Acquisition) 我想将获取的图像显示到图片框,我也想删除该图像。
答案 0 :(得分:1)
我做了你所描述的。我没有将文件保存到磁盘(需要稍后删除),而是将扫描仪的FileData输出读入MemoryStream,可以将其转换为Bitmap对象,可以将其指定为PictureBox.Image。像这样:
Dim CD As New WIA.CommonDialog
Dim F As WIA.ImageFile = CD.ShowAcquireImage(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
PictureBox1.Image = Bmp
'Do a victory dance. It worked!
Catch ex As Exception
MsgBox("An error occurred while converting scan data to a bitmap: " & ex.Message)
End Try
If MStream IsNot Nothing Then MStream.Dispose()
End If
你有它。有点改编自我自己的使用,但希望你不会遇到任何问题。
对于使用此代码的任何其他人,您需要在项目中添加对“Microsoft Windows Image Acquisition Library v2.0”COM组件的引用。