473,372 Members | 1,276 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,372 software developers and data experts.

GetDIBBits does not fill the array corectly

I have another post asking how to fill in the structure but I now think
GetDIBBits is the way, I just can't get it to work!

I can make the following run but GetDIBBits does not fill the array to
correctly reflect the data from the bitmap.

Any helpful suggestions would be appreciated.

Dim hInBitmap As IntPtr = InBitmap.GetHbitmap()

'Dim hInBitmapDC As IntPtr = GetDC(hInBitmap)

Dim hInBitmapDC As IntPtr = GetDC(Nothing)

Dim dibInfo As New BitmapInfo

Dim dibInfoPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dibInfo))

If GetDIBits(hInBitmapDC, hInBitmap, 0, 0, Nothing, dibInfoPtr,
DIB_RGB_COLORS) = 0 Then

DeleteObject(hInBitmap)

Exit Sub

End If

dibInfo = CType(Marshal.PtrToStructure(dibInfoPtr, dibInfo.GetType),
BitmapInfo)

Marshal.FreeHGlobal(dibInfoPtr)

ReleaseDC(hInBitmap, hInBitmapDC)

Above: Don't know which GetDC is correct?

Public Declare Auto Function GetDIBits Lib "gdi32" (ByVal hDC As IntPtr,
ByVal hBitmap As IntPtr, ByVal nStartScan As Integer, ByVal nNumScans As
Integer, ByRef lpBits As Byte, ByRef lpBI As IntPtr, ByVal wUsage As
Integer) As Integer

Above: Do not know how to use lpBI As BitmapInfo - would that be better?

Below: Don't know how to set the array size at run time when I know how many
colors there are?

Public Structure BitmapInfo

Public bmiHeader As BitmapInfoHeader

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)Public bmiColors() As
RGBQuad

End Structure

Public Structure BitmapInfoHeader

Public biSize As Integer

Public biWidth As Integer

Public biHeight As Integer

Public biPlanes As Short

Public biBitCount As Short

Public biCompression As Integer

Public biSizeImage As Integer

Public biXPelsPerMeter As Integer

Public biYPelsPerMeter As Integer

Public biClrUsed As Integer

Public biClrImportant As Integer

End Structure

Public Structure RGBQuad

Public rgbBlue As Byte

Public rgbGreen As Byte

Public rgbRed As Byte

Public rgbReserved As Byte

End Structure


Aug 9 '07 #1
2 2003
>What is the simplest way to get the BitmapInfo info out of a Bitmap?

Using GetObject with DIBSECTION is the best way to get this information.
Dim hInBitmap As IntPtr = InBitmap.GetHbitmap()

Dim dibInfo As New BitmapInfo

Dim dibInfoPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dibInfo))

If GetObject(hInBitmap, Marshal.SizeOf(dibInfo), dibInfoPtr) <>
Marshal.SizeOf(dibInfo) Then

DeleteObject(hInBitmap)

Exit Sub

End If

I'm back to square one.

That's the first thing I tried.

Can't get past it returning zero for a 256 8bpp bitmap

Public Declare Auto Function GetObject Lib "gdi32.dll" (ByVal hObject As
IntPtr, ByVal nCount As Integer, ByVal nEntries As IntPtr) As Integer
Public Structure BitmapInfo

Public bmiHeader As BitmapInfoHeader

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)Public bmiColors() As
RGBQuad

End Structure

Public Structure BitmapInfoHeader

Public biSize As Integer

Public biWidth As Integer

Public biHeight As Integer

Public biPlanes As Short

Public biBitCount As Short

Public biCompression As Integer

Public biSizeImage As Integer

Public biXPelsPerMeter As Integer

Public biYPelsPerMeter As Integer

Public biClrUsed As Integer

Public biClrImportant As Integer

End Structure
Aug 9 '07 #2
just realize I hadn't changed to
Dim dibInfo As New Wnd.DIBSECTION

I do that now

" active" <ac**********@a-znet.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
>>What is the simplest way to get the BitmapInfo info out of a Bitmap?

Using GetObject with DIBSECTION is the best way to get this information.
Dim hInBitmap As IntPtr = InBitmap.GetHbitmap()

Dim dibInfo As New BitmapInfo

Dim dibInfoPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dibInfo))

If GetObject(hInBitmap, Marshal.SizeOf(dibInfo), dibInfoPtr) <>
Marshal.SizeOf(dibInfo) Then

DeleteObject(hInBitmap)

Exit Sub

End If

I'm back to square one.

That's the first thing I tried.

Can't get past it returning zero for a 256 8bpp bitmap

Public Declare Auto Function GetObject Lib "gdi32.dll" (ByVal hObject As
IntPtr, ByVal nCount As Integer, ByVal nEntries As IntPtr) As Integer
Public Structure BitmapInfo

Public bmiHeader As BitmapInfoHeader

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)Public bmiColors()
As RGBQuad

End Structure

Public Structure BitmapInfoHeader

Public biSize As Integer

Public biWidth As Integer

Public biHeight As Integer

Public biPlanes As Short

Public biBitCount As Short

Public biCompression As Integer

Public biSizeImage As Integer

Public biXPelsPerMeter As Integer

Public biYPelsPerMeter As Integer

Public biClrUsed As Integer

Public biClrImportant As Integer

End Structure


Aug 9 '07 #3

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

Similar topics

5
by: Fabio Papa | last post by:
Hi, I am fairly new to programming and and even newer to dotnet. I appoligise in advance if this is a dumb questions, and I would appreciate if you could answer it anyways. :) I am writing a...
5
by: Joe C | last post by:
I'm a hobbiest, and made the forray into c++ from non-c type languages about a year ago. I was "cleaning up" some code I wrote to make it more "c++ like" and have a few questions. I'm comfortable...
4
by: thehuby | last post by:
Is there an acutal function in PHP for removing an element of an array? eg: array1 = ("zero", "one", "two", "three"); array1 = remove_element( array1, 2 ); // array1 now contains ("zero", "one",...
6
by: juli | last post by:
Hello, I need a control which will contain radio buttons that will be added in a loop. I am using this control a source of some other control. I tried to use group box windows control and to add...
52
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it...
2
by: cpisz | last post by:
I saw that using std::fill was the way to go for setting all elements of an array to some value in one foul swoop. However when I tryed it I am getting an error. Can I only use this for vectors...
6
by: valerij | last post by:
Please help. I have been on this problem for a week now. I am using Windows 98SE, Microsoft Visual C++ 6.0 The following program only works when the function is not called, BUT the function does...
0
by: dprjessie | last post by:
Hello, I am a Web programmer and I'm working on my first desktop application as a favor for a friend. I'm sure I have a stupid error here, but there is no error being thrown so I can't figure out...
1
by: bytesFTW99 | last post by:
I have been struggling with this for some time can anyone help out? just trying to have 3 dropdown boxes that fill depending on what is selected, then in some cases click a button and have the second...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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.