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

byte array (of pixels) --> HBITMAP ... how?

321 views
Skip to first unread message

ac

unread,
Oct 23, 2003, 8:31:19 PM10/23/03
to
hello

I allocated a pixel buffer and I have a function that writes the bitmap bits
into it.

Q: how do I create an HBITMAP from this array of bytes?

thanks


vipin

unread,
Oct 24, 2003, 2:09:17 AM10/24/03
to
you may use createdibsection to create a DIB or
CreateBitmap and SetBitmapBits if u want a ddb.
vipin
>.
>

John Hornick [MSFT]

unread,
Oct 24, 2003, 10:01:52 AM10/24/03
to
Hi,


Presuming your bitmap bits are in DIB format, you can use CreateDIBSection()
to create a DIBSection, then memcpy() your bits into the DIBSection. Or you
could use CreateDIBitmap().

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.

ajc

unread,
Oct 27, 2003, 8:47:35 PM10/27/03
to
ok well I have created a DOB but there's something wrong with the colors...
reds show up blue and so on...
is it because I have not set up the bmiColors member of the BITMAPINFO ?
all i have are the raw bitmap image bits..no color tables.. how do I set
that up?

so far i've got:

int w, h;
unsigned int nBytes;

BYTE* bits = GetRawBitmapBits(&w, &h, &nBytes); // allocs the bit buffer and
fills it

BITMAPINFO bmi;
memset (&bmi, 0, sizeof(BITMAPINFO));

bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = hehight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = nBytes;

//bmi.bmiColors = ????

BYTE* dibBits = NULL;

HBITMAP hBM = CreateDIBSection( hDC, &bmi,DIB_RGB_COLORS,(void**)&dibBits,
NULL, NULL );

SetDIBits(hDC, hBM, 0, h, buff, &bmi, DIB_RGB_COLORS); //copies my bits
into the DIB

free (bits);

return hBM


thanks!

"John Hornick [MSFT]" <JHor...@online.microsoft.com> wrote in message
news:VhTdjdjm...@cpmsftngxa06.phx.gbl...

John Hornick [MSFT]

unread,
Oct 28, 2003, 1:16:49 PM10/28/03
to
Hi,

You probably have the image bits in the wrong order. DIBs are stored
in BGR - loop through the image bits and swap the R and G bytes.

0 new messages