D
Daniel Friend
Hello,
I have a question. I would like to know how I can convert the Video Header
to a bitmap in VB .NET
I searched everywhere and could not see how to do this. This is as far as I
get. I am getting the cam preview to work and it is calling the
FrameCallbackTarget function just fine... I just need to make the stream
frame a bitmap.
Any help would be greatly appreciated!!!!
Thanks,
Dan
Here is my code:
Delegate Function CallBackDelegate(ByVal hwnd As IntPtr, ByRef lpVHdr As
VIDEOHDR) As IntPtr
Public delCallBack As CallBackDelegate = New CallBackDelegate(AddressOf
FrameCallbackTarget)
Public Declare Function SendMessage2 Lib "user32.dll" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal
lParam As CallBackDelegate) As IntPtr
Structure VIDEOHDR
Dim lpData As Integer '// address of video buffer
Dim dwBufferLength As Integer '// size, in bytes, of the Data buffer
Dim dwBytesUsed As Integer '// see below
Dim dwTimeCaptured As Integer '// see below
Dim dwUser As Integer '// user-specific data
Dim dwFlags As Integer '// see below
<VBFixedArray(3)> Dim dwReserved() As Integer '// reserved; do not use}
End Structure
Private Sub StartCam()
Dim iHeight As Integer = PictureBox1.Height
Dim iWidth As Integer = PictureBox1.Width
hHwnd = capCreateCaptureWindowA(iDevice.ToString, WS_VISIBLE Or
WS_CHILD, 0, 0, 320, 240, PictureBox1.Handle.ToInt32, 0)
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, PictureBox1.Width,
PictureBox1.Height, SWP_NOMOVE Or SWP_NOZORDER)
SendMessage2(New IntPtr(hHwnd), WM_CAP_SET_CALLBACK_FRAME, New
IntPtr(0), delCallBack)
Else
DestroyWindow(hHwnd)
End If
end sub
Public Function FrameCallbackTarget(ByVal hwnd As IntPtr, ByRef lpVHdr As
VIDEOHDR) As IntPtr
Dim oBMP As New Bitmap(640, 480, 640 * 3,
Imaging.PixelFormat.Format24bppRgb, New System.IntPtr(lpVHdr.lpData))
PictureBox2.Image = oBMP
End Function
I have a question. I would like to know how I can convert the Video Header
to a bitmap in VB .NET
I searched everywhere and could not see how to do this. This is as far as I
get. I am getting the cam preview to work and it is calling the
FrameCallbackTarget function just fine... I just need to make the stream
frame a bitmap.
Any help would be greatly appreciated!!!!
Thanks,
Dan
Here is my code:
Delegate Function CallBackDelegate(ByVal hwnd As IntPtr, ByRef lpVHdr As
VIDEOHDR) As IntPtr
Public delCallBack As CallBackDelegate = New CallBackDelegate(AddressOf
FrameCallbackTarget)
Public Declare Function SendMessage2 Lib "user32.dll" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal
lParam As CallBackDelegate) As IntPtr
Structure VIDEOHDR
Dim lpData As Integer '// address of video buffer
Dim dwBufferLength As Integer '// size, in bytes, of the Data buffer
Dim dwBytesUsed As Integer '// see below
Dim dwTimeCaptured As Integer '// see below
Dim dwUser As Integer '// user-specific data
Dim dwFlags As Integer '// see below
<VBFixedArray(3)> Dim dwReserved() As Integer '// reserved; do not use}
End Structure
Private Sub StartCam()
Dim iHeight As Integer = PictureBox1.Height
Dim iWidth As Integer = PictureBox1.Width
hHwnd = capCreateCaptureWindowA(iDevice.ToString, WS_VISIBLE Or
WS_CHILD, 0, 0, 320, 240, PictureBox1.Handle.ToInt32, 0)
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, PictureBox1.Width,
PictureBox1.Height, SWP_NOMOVE Or SWP_NOZORDER)
SendMessage2(New IntPtr(hHwnd), WM_CAP_SET_CALLBACK_FRAME, New
IntPtr(0), delCallBack)
Else
DestroyWindow(hHwnd)
End If
end sub
Public Function FrameCallbackTarget(ByVal hwnd As IntPtr, ByRef lpVHdr As
VIDEOHDR) As IntPtr
Dim oBMP As New Bitmap(640, 480, 640 * 3,
Imaging.PixelFormat.Format24bppRgb, New System.IntPtr(lpVHdr.lpData))
PictureBox2.Image = oBMP
End Function