From: Gernot Frisch on
This is my code for making a dummy 24 bit DIB and trying to convert to
a HBITMAP.
The image shows up black, the size is OK.

# # #

int w,h,w2;
w=320; h=140; w2=320/*4 byte align*/;

char* pImageBits = new char[w2*h*3];
// dummy colors
for(int i=0; i<w*h; ++i){*pImageBits = RGB(rand(), rand(), rand());
++pImageBits;}


BITMAPINFO bi;
memset(&bi, 0, sizeof(bi));
bi.bmiHeader.biBitCount=24;
bi.bmiHeader.biHeight=h;
bi.bmiHeader.biPlanes=1;
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth=w;
bi.bmiHeader.biXPelsPerMeter = 96;
bi.bmiHeader.biYPelsPerMeter = 96;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = w2*h*3;

HDC hdc;
hdc = GetDC(NULL);
HBITMAP hbm = ::CreateDIBitmap(hdc, (BITMAPINFOHEADER*)&bi,
CBM_INIT,
pImageBits, &bi, DIB_RGB_COLORS);
this->CreateIndirect(hbm);
ReleaseDC(NULL, hdc);
delete[] pImageBits;
# # #

The CreateIndirect does:
# # #
Clear();
m_Bitmap = CopyBitmap(CBitmap::FromHandle(hSrcBitmap));
# # #


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


From: Alex Fedotov on
Gernot Frisch wrote:

> This is my code for making a dummy 24 bit DIB and trying to convert to a
> HBITMAP.
> The image shows up black, the size is OK.

Avoid using CreateDIBitmap, use CreateDIBSection instead.

The bitmap created by CreateDIBitmap has the same color depth as the passed
in device context. Since the device context obtained by GetDC initially
contains a 1x1 monochrome bitmap, your code ends up creating a monochrome
bitmap out of the RGB array.

-- Alex Fedotov

>
> # # #
>
> int w,h,w2;
> w=320; h=140; w2=320/*4 byte align*/;
>
> char* pImageBits = new char[w2*h*3];
> // dummy colors
> for(int i=0; i<w*h; ++i){*pImageBits = RGB(rand(), rand(), rand());
> ++pImageBits;}
>
>
> BITMAPINFO bi;
> memset(&bi, 0, sizeof(bi));
> bi.bmiHeader.biBitCount=24;
> bi.bmiHeader.biHeight=h;
> bi.bmiHeader.biPlanes=1;
> bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> bi.bmiHeader.biWidth=w;
> bi.bmiHeader.biXPelsPerMeter = 96;
> bi.bmiHeader.biYPelsPerMeter = 96;
> bi.bmiHeader.biCompression = BI_RGB;
> bi.bmiHeader.biSizeImage = w2*h*3;
>
> HDC hdc;
> hdc = GetDC(NULL);
> HBITMAP hbm = ::CreateDIBitmap(hdc, (BITMAPINFOHEADER*)&bi, CBM_INIT,
> pImageBits, &bi, DIB_RGB_COLORS);
> this->CreateIndirect(hbm);
> ReleaseDC(NULL, hdc);
> delete[] pImageBits;
> # # #
>
> The CreateIndirect does:
> # # #
> Clear();
> m_Bitmap = CopyBitmap(CBitmap::FromHandle(hSrcBitmap));
> # # #
>
>
> --
> -Gernot
> int main(int argc, char** argv) {printf ("%silto%c%cf%cgl%ssic%ccom%c",
> "ma", 58, 'g', 64, "ba", 46, 10);}
>
> ________________________________________
> Looking for a good game? Do it yourself!
> GLBasic - you can do
> www.GLBasic.com
>
>

From: Gernot Frisch on

> The bitmap created by CreateDIBitmap has the same color depth as the
> passed
> in device context. Since the device context obtained by GetDC
> initially contains a 1x1 monochrome bitmap, your code ends up
> creating a monochrome bitmap out of the RGB array.

GetDC(NULL) is the desktop window's DC - isn't it?


From: Grzegorz Wróbel on
Did you initialize the generator?

Gernot Frisch wrote:

> This is my code for making a dummy 24 bit DIB and trying to convert to
> a HBITMAP.
> The image shows up black, the size is OK.
>
> # # #
>
> int w,h,w2;
> w=320; h=140; w2=320/*4 byte align*/;
>
> char* pImageBits = new char[w2*h*3];
> // dummy colors
> for(int i=0; i<w*h; ++i){*pImageBits = RGB(rand(), rand(), rand());
> ++pImageBits;}
>
>
> BITMAPINFO bi;
> memset(&bi, 0, sizeof(bi));
> bi.bmiHeader.biBitCount=24;
> bi.bmiHeader.biHeight=h;
> bi.bmiHeader.biPlanes=1;
> bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> bi.bmiHeader.biWidth=w;
> bi.bmiHeader.biXPelsPerMeter = 96;
> bi.bmiHeader.biYPelsPerMeter = 96;
> bi.bmiHeader.biCompression = BI_RGB;
> bi.bmiHeader.biSizeImage = w2*h*3;
>
> HDC hdc;
> hdc = GetDC(NULL);
> HBITMAP hbm = ::CreateDIBitmap(hdc, (BITMAPINFOHEADER*)&bi,
> CBM_INIT,
> pImageBits, &bi, DIB_RGB_COLORS);
> this->CreateIndirect(hbm);
> ReleaseDC(NULL, hdc);
> delete[] pImageBits;
> # # #
>
> The CreateIndirect does:
> # # #
> Clear();
> m_Bitmap = CopyBitmap(CBitmap::FromHandle(hSrcBitmap));
> # # #
>
>

--
677265676F727940346E6575726F6E732E636F6D
From: Gernot Frisch on
> Did you initialize the generator?

What does that mean?


 |  Next  |  Last
Pages: 1 2 3
Prev: mystery thread
Next: eject cd?