"BeeJ" <
nos...@spamnot.com> wrote in message
news:k748tg$3nj$1...@speranza.aioe.org...
> Is there a way to directly go from the WebCam frame callback to a bitmap
> array? i.e. without using the intermediate picbox.
> Currently I can do this as a two step process.
> Step one:
> In the callback I receive the pic data as pData. [***]
> StretchDIBits Picbox.hdc, 0, 0, w, h, 0, 0, w, h, ByVal pData,
> m_tBI, DIB_RGB_COLORS, vbSrcCopy
> ' this puts the full image in a picturebox.
> Step Two:
> In another method
> lRet = GetObject(picbox.Image.Handle, Len(m_hBmp), m_hBmp)
> ' Put into an array
> lRet = GetBitmapBits(picbox.Image.Handle, m_hBmp.bmWidthBytes *
> m_hBmp.bmHeight, m_abImgByte(0, 0, 0))
> Now I can cycle through the array as needed.
> How would I go from the pData directly into the array?
You haven't said exactly what you are getting in pData (see the line marked
[***] above). Is the data compressed, or is it straight bitmap data? If it
is not compressed (if you are currently using BI_RGB for the biCompression
member of your BITMAPINFOHEADER structure) then you should not need to do
either of the above things. All you should need to do is declare a dynamic
VB array, of either Bytes or Longs as appropriate depending on the number of
bits per pixel of your data (the value you currently have in the biBitCount
member of your BITMAPINFOHEADER structure), and also depending on how you
want to handle the data. This declaration of a dynamic VB array effectively
takes no time at all of course. Then you can use a SAFEARRAY structure to
"point" the dynamic VB array at your pData, which also effectively takes no
time at all (the actual bitmap data pointed at by pData stays exactly where
it is, with your VB array being able to examine or manipulate it directly).
You need to take account of the fact there will be some padding bytes at the
end of each scanline in pData if the pixel width of your image and the bits
per pixel it uses causes each horizontal scanline to occupy something other
than a whole multiple of four bytes, but even if this is the case (which it
is probably not) then you can easily work around it. If the pixel width of
your bitmap at pData is itself a multiple of four pixels (the pixel height
doesn't matter) then you don't need to worry about that last part I
mentioned at all, regardless of how many bits per pixel it uses. Anyway,
that's all I'm going to say on this matter. The rest is up to you.
First check out the format of DIBSections:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183567(v=vs.85).aspx
. . . and and then check out SAFEARRAY structures:
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms221482(v=vs.85).aspx
. . . and then check out how you can use SAFEARRAY structures to "point"
standard VB arrays at an existing block of data in memory, various examples
of which you'll find in the archives for this group and others (but before
you do either of those things check that you are not dealing with a
compressed bitmap).
Should be good homework for you ;-)
Mike