Solved

How to make raw bitmap data usable

Posted on 2010-11-16
2
507 Views
Last Modified: 2012-05-10
Hello, I have some camera hardware that -- using the provided sample code -- I am able to use their functions to pull raw data out of (it says that it is in RGB24 format) and there is some other code that seems to create a corresponding BITMAPINFOHEADER structure.  But I don't know how to turn this into something I can use.  To clarify, below is the code.



    Structure LUCAM_FRAME_FORMAT
        Dim xOffset As Integer
        Dim yOffset As Integer
        Dim width As Integer
        Dim height As Integer
        Dim pixelFormat As Integer
        Dim subSampleX As Short
        Dim flagsX As Short
        Dim subSampleY As Short
        Dim flagsY As Short
    End Structure

 Public FrameFormat As LUCAM_FRAME_FORMAT

Public BitmapFrame() As Byte
...

LucamGetFormat(hCamera, myFrameFormat, FrameRate)

        ret = LucamConvertFrameToRgb24(hCamera, BitmapFrame, MyFrame, FrameFormat.width, FrameFormat.height, FrameFormat.pixelFormat, Conversion)

Open in new window


which apparently returns the image data in the BitmapFrame array, and then it creates a standard BITMAPINFOHEADER structure with the following

  Dim bmpInfo As BITMAPINFOHEADER

        ' Display captured frame
        bmpInfo.biBitCount = 24
        bmpInfo.biClrImportant = 0
        bmpInfo.biClrUsed = 0
        bmpInfo.biCompression = 0 ' BI_RGB
        bmpInfo.biHeight = FrameFormat.height
        bmpInfo.biPlanes = 1
        bmpInfo.biSize = 40 ' SizeOf(BITMAPINFOHEADER)
        bmpInfo.biSizeImage = FrameFormat.width * FrameFormat.height * 3
        bmpInfo.biWidth = FrameFormat.width
        bmpInfo.biXPelsPerMeter = 0
        bmpInfo.biYPelsPerMeter = 0

Open in new window


and then it does some other things with this data (feeds it into its own functions) that are not useful to me.  what I need to do is stop it here, and turn the data into my own .NET System.Drawing.Bitmap object so that I can do whatever I want with it.

But so far I have not been able to string together the code to convert the raw byte array, that apparently matches up with this BITMAPINFOHEADER, into my own .NET bitmap.  Does anyone have any suggestions?  

Thanks VERY much in advance.


0
Comment
Question by:riceman0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 34155896
That is a great question, but one without a specific answer from me.  I do have some code to export a frame from an .avi file to a Bitmap, that might prove useful as food for thought.


Public Sub ExportBitmap(ByVal position As Integer, ByVal dstFileName As String)
		If position > CountFrames Then
			Throw New Exception("Invalid frame position")
		End If
		Dim pDib As Integer = Avi.AVIStreamGetFrame(m_getFrameObject, m_firstFrame + position)
		Dim bih As Avi.BITMAPINFOHEADER = New Avi.BITMAPINFOHEADER
		bih = CType(Marshal.PtrToStructure(New IntPtr(pDib), bih.GetType), Avi.BITMAPINFOHEADER)
		If bih.biSizeImage < 1 Then
			Throw New Exception("Exception in AVIStreamGetFrame: Not bitmap decompressed.")
		End If
		Dim bitmapData(bih.biSizeImage) As Byte
		Dim address As Integer = pDib + Marshal.SizeOf(bih)
		For offset As Integer = 0 To bitmapData.Length - 1
			bitmapData(offset) = Marshal.ReadByte(New IntPtr(address))
			address += 1
		Next offset
		Dim bitmapInfo(Marshal.SizeOf(bih)) As Byte
		Dim ptr As IntPtr = Marshal.AllocHGlobal(bitmapInfo.Length)
		Marshal.StructureToPtr(bih, ptr, False)
		address = ptr.ToInt32
		For offset As Integer = 0 To bitmapInfo.Length - 1
			bitmapInfo(offset) = Marshal.ReadByte(New IntPtr(address))
			address += 1
		Next offset
		Dim bfh As Avi.BITMAPFILEHEADER = New Avi.BITMAPFILEHEADER
		bfh.bfType = Avi.BMP_MAGIC_COOKIE
		bfh.bfSize = 55 + bih.biSizeImage
		bfh.bfReserved1 = 0
		bfh.bfReserved2 = 0
		bfh.bfOffBits = Marshal.SizeOf(bih) + Marshal.SizeOf(bfh)

        Using fs As New FileStream(dstFileName, System.IO.FileMode.Create)

            Dim bw As New BinaryWriter(fs)

            bw.Write(bfh.bfType)
            bw.Write(bfh.bfSize)
            bw.Write(bfh.bfReserved1)
            bw.Write(bfh.bfReserved2)
            bw.Write(bfh.bfOffBits)
            bw.Write(bitmapInfo)
            bw.Write(bitmapData)
            bw.Close()
        End Using

End Sub

Open in new window

0
 

Author Comment

by:riceman0
ID: 34158337

That gave me enough ammunition to post a question back to the vendor, thanks.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question