i have a program that will capture an image using webcam using this source code…
http://www.thaiio.com/prog-cgi/vbnetwebcam.html
and this is the Sub that will get the image from the clipboard and convert it to Bitmap…
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim data As IDataObject
Dim bmap As Bitmap
'
' Copy image to clipboard
'
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
'
' Get image from clipboard and convert it to a bitmap
'
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
picCapture.Image = bmap
ClosePreviewWindow()
btnSave.Enabled = False
btnStop.Enabled = False
btnStart.Enabled = True
btnInfo.Enabled = False
Trace.Assert(Not (bmap Is Nothing))
sfdImage.Filter = ("Jpeg|*.jpg")
If sfdImage.ShowDialog = DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Jpeg)
End If
End If
End Sub
i get an error “Value cannot be null. Parameter name: encoder”
when trying to save it on a Memorystream, maybe because i should get the original format first. any idea on how can i do it?
Sorry for posting this question, i figured out the answer. thx for the help.
Dim ms As New MemoryStream()
bmap.Save(ms, Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = ms.GetBuffer
ms.Close()