473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

AVICAP32 and VIDEOHDR to Bitmap

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
Nov 21 '05 #1
1 5327
Hi,

"Daniel Friend" <Da******@noemail.noemail> wrote in message
news:ur*************@tk2msftngp13.phx.gbl...
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
Your code seems to work, what is the problem you have with the Bitmap ? You
may want to check if
lpVHdr.dwBufferLength == stride * height .

And a warning which i'm sure isn't causing your problem now but anyway you
should always use IntPtr inside a function sign or structure where a pointer
or handle was used unmanaged (except for function pointers where you may use
a delegate).

HTH,
Greetings





Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sharon | last post by:
I encountered a strange behavior when doing ‘new Bitmap’: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: ...
3
by: Workgroups | last post by:
I'm writing a piece of video software, sort of like a webcam, that's meant to show a preview on the screen from any WDM capable cam. I want to give the user RGB sliders, and process each frame by...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
2
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
5
by: =?Utf-8?B?QVRU?= | last post by:
I have a bitmap of 100X100. On the load, the bitmap is created by a function (createimage()). On my OnPaint, I draw the image back to the screen (e.Graphics.DrawImage( bitmap, destrect)). Now,...
1
by: Macias | last post by:
Hi, I'm using avicap32 to capture video from my webcam, but I've a problem. I can cerate preview in ex. in picturebox component, but I need to get image from camera to Bitmap or Image component,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.