title: How to draw transparent BMP with GDI+
body: <p>I'm currently editing some old GDI code to use GDI+ and ran into a problem when it comes to draw a BMP file with transparent background. The old GDI code did not use any obvious extra code to draw the background transparent so I'm wondering how to achieve this using GDI+.</p>
  
  <p>My current code looks like this</p>
  
  <pre><code>HINSTANCE hinstance = GetModuleHandle(NULL);
  bmp = Gdiplus::Bitmap::FromResource(hinstance, MAKEINTRESOURCEW(IDB_BMP));
  Gdiplus::Graphics graphics(pDC-&gt;m_hDC);
  graphics.DrawImage(&amp;bmp, posX, posY);
  </code></pre>
  
  <p>I also tried to create a new bitmap from the resource by using the clone method and by drawing the bitmap to a newly created one but neither did help. Both times I used PixelFormat32bppPARGB.</p>
  
  <p>Then I tried to use alpha blending but this way the whole image gets transparent and not only the background:</p>
  
  <pre><code>Gdiplus::ColorMatrix clrMatrix = { 
      1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
      0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
      0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
      0.0f, 0.0f, 0.0f, 0.5f, 0.0f,
      0.0f, 0.0f, 0.0f, 0.0f, 1.0f
  };
  
  Gdiplus::ImageAttributes imgAttr;
  imgAttr.SetColorMatrix(&amp;clrMatrix);
  
  graphics.DrawImage(&amp;bmp, destRect, 0, 0, width(), height(), Gdiplus::UnitPixel, &amp;imgAttr);
  </code></pre>
  
  <p>The transparency information is already contained in the image but I don't have a clue how to apply it when drawing the image. How does one achieve this?</p>