-
August 22nd, 2005, 08:46 AM
#1
CreateDIBSection gives me black bitmap
Code:
HDC hMemDC = CreateCompatibleDC(NULL);
LPVOID pBit32;
HBITMAP bmp = CreateDIBSection(hMemDC,pBmi,DIB_RGB_COLORS, &pBit32, NULL, 0);
DeleteDC(hMemDC);
How to solve it?
Thanks
-
August 22nd, 2005, 08:51 AM
#2
Re: CreateDIBSection gives me black bitmap
well its black cause probably one of your parameter is incorrect.
its hard to tell what since you didnt post how you init all the params say like
pBmi.
anyway take a look at this Thread i already post some code that use the ::CreateDIBSection(..), it should help you out
Cheers
-
August 22nd, 2005, 08:57 AM
#3
Re: CreateDIBSection gives me black bitmap
bmi comes from
Code:
BITMAPINFO* bmi;
if ( OpenClipboard() )
{
HGLOBAL hglb = NULL;
if ((hglb = GetClipboardData(CF_DIB)))
{
switch (format) {
case CF_DIB:
{
bmi = (BITMAPINFO*) GlobalLock(hglb);
...
And the clipboard is definitely containing a picture in CF_DIB format (I checked using some clipboard program I found in an article on codeguru; I also get into the right case in the switch statement).
-
August 22nd, 2005, 09:37 AM
#4
Re: CreateDIBSection gives me black bitmap
well if you want to get the Bitmap from the clipboard the i can give you a sample but it doent work with DIB, is it matter to you?
anyway check this out:
Code:
if ( ::OpenClipboard(0) )
{
HGLOBAL hglb = ::GetClipboardData(CF_BITMAP);
if (hglb )
{
CBitmap *bmp = CBitmap::FromHandle((HBITMAP)hglb);
BITMAP b;
bmp->GetBitmap(&b);
int size = (b.bmBitsPixel/8)*b.bmHeight*b.bmWidth;
BYTE *lpBits = new BYTE[size];
bmp->GetBitmapBits(size,lpBits);
// use lpBits
delete []lpBits;
}
::CloseClipboard();
}
Cheers
-
August 22nd, 2005, 09:45 AM
#5
Re: CreateDIBSection gives me black bitmap
That's very nice, thanks alot.
The only thing is, I need this e.g. when a user browses to a webpage with internet explorer and wants to use an image he sees in my program. I want to do this using the clipboard (right mouse click, copy on the image in internet explorer), but it seems that when it is copied in the clipboard it has the format CF_DIB instead of CF_BITMAP.
-
August 22nd, 2005, 10:01 AM
#6
Re: CreateDIBSection gives me black bitmap
i tried to use the same code posted you i just replaced the CF_BITMAP with CF_DIB and its also working...
try it out and let me see if its working for you.
Cheers
-
August 22nd, 2005, 10:17 AM
#7
Re: CreateDIBSection gives me black bitmap
Indeed, it works great!
Thanks alot Golanshahar.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|