CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Posts
    218

    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

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Feb 2005
    Posts
    218

    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).

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    Feb 2005
    Posts
    218

    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.

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  7. #7
    Join Date
    Feb 2005
    Posts
    218

    Talking 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
  •  





Click Here to Expand Forum to Full Width

Featured