title: Transparency on white background bitmap C++ winapi
body: <p>well i have a question about transparency in a bitmap file which i want to save as png file, at the moment i take a screenshot of the cursor in the system and  save it as png, this work fine whit arrow, hand and other cursors but in the moment of use cursors like I-beam or "not" cursor this have a problem, the explanation is that each cursor have a mask and a color bitmap which combine and result in a transparent cursor but I-beam and others no have color bitmap, them have only mask that contains the color and mask in the same bitmap, i refer this post: <a href="https://stackoverflow.com/questions/918990/c-capturing-the-mouse-cursor-image">C# - Capturing the Mouse cursor image</a> well they use C# but the idea is the same.</p>
  
  <p>in my code i use C++ and i manage to create a cursor but with white background color, i don't know how to convert it in transparent color, in the post i refer use a function MakeTransparent, any idea? thanks for the help :D</p>
  
  <pre><code>    CURSORINFO cursor;
      ICONINFO cursorIconInfo;
      HICON cursorIcon;
      cursor.cbSize=sizeof(CURSORINFO);
      GetCursorInfo(&amp;cursor);
      GetIconInfo(cursor.hCursor,&amp;cursorIconInfo);
      //cursorIcon=CopyIcon(cursor.hCursor);
      //GetIconInfo(LoadCursor(NULL,IDC_ARROW),&amp;cursorIconInfo);
      //cursorIcon=CreateIconIndirect(&amp;cursorIconInfo);
  
      CxImage* imag=new CxImage();
      /*imag-&gt;CreateFromHICON(cursorIcon);
      imag-&gt;Save("cursor.png",CXIMAGE_FORMAT_PNG);*/
      BITMAP bm;
      //CImage* imag=new CImage();
      GetObject(cursorIconInfo.hbmMask,sizeof(BITMAP),&amp;bm);
      if(bm.bmHeight == bm.bmWidth*2){
          HDC screendc=CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
          HDC cursormaskDC=CreateCompatibleDC(screendc);
          HDC cursorfinalDC=CreateCompatibleDC(screendc);
  
          HBITMAP cursormask=CreateCompatibleBitmap(screendc,bm.bmWidth,bm.bmWidth);
          HBITMAP cursorfinal=CreateCompatibleBitmap(screendc,bm.bmWidth,bm.bmWidth);
  
          SelectObject(cursormaskDC,cursorIconInfo.hbmMask);
          SelectObject(cursorfinalDC,cursorfinal);
  
          BitBlt(cursorfinalDC,0,0,bm.bmWidth,bm.bmWidth,cursormaskDC,0,bm.bmWidth,SRCCOPY); 
          BitBlt(cursorfinalDC,0,0,bm.bmWidth,bm.bmWidth,cursormaskDC,0,0,SRCINVERT);
  
          /*cursorIconInfo.hbmColor=cursorcolor;
          cursorIconInfo.hbmMask=cursormask;
          cursorIcon=CreateIconIndirect(&amp;cursorIconInfo);
          imag-&gt;CreateFromHICON(cursorIcon);
          imag-&gt;Save("cursorPrub.png",CXIMAGE_FORMAT_PNG);*/
          imag-&gt;CreateFromHBITMAP(cursorfinal);
  
          imag-&gt;Save("cursor.png",CXIMAGE_FORMAT_PNG);
          DeleteObject(cursorIconInfo.hbmMask);
          DeleteObject(cursorIconInfo.hbmColor);
          DestroyIcon(cursorIcon);
  
          imag-&gt;Destroy();
          return;
      }
  </code></pre>