Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the BITMAPINFO from an HBITMAP

2 views
Skip to first unread message

John Quinley

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
I am basically creating texts that I will be blitting onto a 256 color
DIB. I cannot guarantee that the DC will be in 256 colors, and most of
the time, it will be in 16-bit color mode. I create a bitmap from the
string using standard windows functions. I then pass that newly created
bitmap to a conversion routine, which will convert it to 256 colors,
using the game's palette.

The problem comes in with 16-bit displays. I need the
BITMAPINFO.bmiColors[1] to determine what my masks are going to be for
RGB. Since Windows is creating the Bitmap, I never have access to the
BITMAPINFO and I don't know how to get it. I need it so I can go through
and convert each 16-bit word in the bitmap data to its proper RGB value.
I know 16-bit displays usually map the 16 bits to 5-5-5 or 5-6-5 bits
for RGB, but I need to be able to determine exactly how it is doing it.

I have a CBitmap object with access to the HBITMAP to get the informatio
by. Thanks in advance.


L.J. Wischik

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
John Quinley <jqui...@spamsucksaros.net> wrote:
>RGB. Since Windows is creating the Bitmap, I never have access to the
>BITMAPINFO and I don't know how to get it. I need it so I can go through
>I have a CBitmap object with access to the HBITMAP to get the informatio
>by. Thanks in advance.

You'll kick yourself...
BITMAP bmp; GetObject(hbm,sizeof(bmp),&bmp);
if it's a plain bitmap or
DIBSECTION dibs; GetObject(hbm,sizeof(dibs),&dibs);
if it's a DIBSection.

--
Lucian Wischik, Queens' College, Cambridge CB3 9ET. www.wischik.com/lu

John Quinley

unread,
Feb 2, 1999, 3:00:00 AM2/2/99
to L.J. Wischik
Thanks for the info. I already knew how to the the BITMAP object from the
HBITMAP. The problem is, the BITMAP object doesn't contain the information I
need to determine how the 16-bit pixels are being masked. What I need is the
BITMAPINFO structure, which contains a BITMAPINFOHEADER object and an array
of RGBQUADS.

struct BITMAPINFO
{
BITMAPINFOHEADER bmi;
RGBQUAD bmiColors[1];
}

When the display is running in 16-bit mode, each pixel is represented by a
16-bit value, with 5 or 6 bits representing RGB, depending on the hardware.
bmiColors contains 3 entries, which translate into masks that I can use to
determine how many bits in the 16-bit pixel is being used for each color.

My problem starts with the fact that the game I'm editing creates bitmaps
using standard Windows functions (such as CreateDIBitmap()), etc. It is
creating bitmaps that are compatible with the display. It then passes the
HBITMAP to a conversion routine that I created to convert the HBITMAP to an
8-bit palettized bitmap. I do not know how to determine the masking for the
16-bit pixels in the HBITMAP. I need the BITMAPINFO object associated with
the HBITMAP to do this, or, if there is another method to determine this
information, that would work as well.

BTW, I am working with Windows 3.1 code.

Thanks for any help you can provide.

Chris Becke

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
John Quinley wrote:

>Thanks for the info. I already knew how to the the BITMAP object from the
>HBITMAP. The problem is, the BITMAP object doesn't contain the information
I
>need to determine how the 16-bit pixels are being masked. What I need is
the
>BITMAPINFO structure, which contains a BITMAPINFOHEADER object and an array
>of RGBQUADS.

GetDIBits should do what you want... (not that I understand why you need
it)...

Call GetDIBits once passing in a BITMAPINFO* and NULL for lpvBits. That will
fill in the struct with the caracteristics of the bitmap selected in the DC.

I don't understand what your "conversion" function is doing however that
makes this necessary. HBITMAPS are opaque in that you can never access their
internal data directly anyway.

Chris
--
My email address is ROT13 encoded to prevent spam: <pue...@zvpebtnzvat.pbz>
My Windows Development pages : <http://users.lia.net/chris/win32>


John W. Quinley

unread,
Feb 5, 1999, 3:00:00 AM2/5/99
to
Chris Becke wrote:

I took your advice and tried the GetDIBits with NULL for lpvBits. The
only thing Win31 did for me was fill in the biSizeImage of the
BITMAPINFOHEADER struct. It still left the bmiColors blank. I was hoping
it would fill in the first 3 of bmiColors with the masks for RGB, but to
no avail. What I need is a way to determine in Windows 3.1 how the video
card is going to structure each 16-bit word in a 16-bit bitmap, whether
5-5-5 or 5-6-5. Thanks for your input.


vcard.vcf

Chris Becke

unread,
Feb 7, 1999, 3:00:00 AM2/7/99
to
>I took your advice and tried the GetDIBits with NULL for lpvBits. The
>only thing Win31 did for me was fill in the biSizeImage of the
>BITMAPINFOHEADER struct. It still left the bmiColors blank. I was hoping
>it would fill in the first 3 of bmiColors with the masks for RGB, but to
>no avail. What I need is a way to determine in Windows 3.1 how the video
>card is going to structure each 16-bit word in a 16-bit bitmap, whether
>5-5-5 or 5-6-5. Thanks for your input.

hmmm, I still don't understand what API you are using that requires you to
know this information. The reason its ahrd to find is that 99% of the time
its not needed (and should not be needed 100% of the time).

If you can explain the API you are trying to use with what kind of bitmap
(DDB or DIB) prehaps I can figure out how to get the information you
require.

Mike Enright

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
"John W. Quinley" <JQui...@aros.net> wrote:

>
>I took your advice and tried the GetDIBits with NULL for lpvBits. The
>only thing Win31 did for me was fill in the biSizeImage of the
>BITMAPINFOHEADER struct. It still left the bmiColors blank. I was hoping
>it would fill in the first 3 of bmiColors with the masks for RGB, but to
>no avail. What I need is a way to determine in Windows 3.1 how the video
>card is going to structure each 16-bit word in a 16-bit bitmap, whether
>5-5-5 or 5-6-5. Thanks for your input.
>

First, though you are using Windows 3.1, try following my GetDIBits
sample at http://www.users.cts.com/sd/m/menright/display.html . The
code is meant for Win32, but it might work for you. It is a little bit
different from what Chris Becke said to do, but maybe that little bit
will put it over the top for you, especially given Win3.1.

Second, if that doesn't work, there is an alternative, which is pretty
ugly. One description of the alternative is article Q195829 in the MS
KnowledgeBase.
(This URL might just fetch it for you:
http://support.microsoft.com/support/kb/articles/q195/8/29.asp?FR=0
)

I mention it because it returns that bit-field information by using
SetPixel and GetPixel, and it might just work in Win3.1, UNLESS there
are subtleties in those functions which I haven't foreseen.

HTH

--
Mike Enright
enri...@acm.org (Email replies cheerfully ignored, use the news group)
http://www.users.cts.com/sd/m/menright/
Cardiff-by-the-Sea, California, USA


Wolfe Exeter

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
A totally different approach would be to utilise Microsoft Active Accessibility
and the DDI Hook. It provides information about all DDI calls and allows you
to access the PDEVICE structures (and thus also the BITMAPINFO) for both source
and destinations in any DDI call.

More info at:
http://www.microsoft.com/enable

Note, MSAA (active accessibility) is built into Win98.


--Wolfe.


0 new messages