How to solve it?Code:HDC hMemDC = CreateCompatibleDC(NULL);
LPVOID pBit32;
HBITMAP bmp = CreateDIBSection(hMemDC,pBmi,DIB_RGB_COLORS, &pBit32, NULL, 0);
DeleteDC(hMemDC);
Thanks
Printable View
How to solve it?Code:HDC hMemDC = CreateCompatibleDC(NULL);
LPVOID pBit32;
HBITMAP bmp = CreateDIBSection(hMemDC,pBmi,DIB_RGB_COLORS, &pBit32, NULL, 0);
DeleteDC(hMemDC);
Thanks
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
bmi comes from
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).Code:BITMAPINFO* bmi;
if ( OpenClipboard() )
{
HGLOBAL hglb = NULL;
if ((hglb = GetClipboardData(CF_DIB)))
{
switch (format) {
case CF_DIB:
{
bmi = (BITMAPINFO*) GlobalLock(hglb);
...
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
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.
i tried to use the same code posted you i just replaced the CF_BITMAP with CF_DIB and its also working...:D
try it out and let me see if its working for you.
Cheers
Indeed, it works great!
Thanks alot Golanshahar.