티스토리 뷰

Show

GdiPlus::Image to CBitmap conversion

Hide Code 2009. 4. 25. 23:44
http://www.codeguru.com/forum/showthread.php?t=344315

Draw the image in a memory device context in which the CBitmap object is selected.
Like in next example:

using namespace Gdiplus;
Image* pImage = Image::FromFile(L"c:\\test.gif");
Status status = pImage->GetLastStatus();
if(Ok == status)
{
   CDC dc;
   dc.CreateCompatibleDC(NULL);
   CBitmap bitmap;
   bitmap.CreateCompatibleBitmap(&dc, pImage->GetWidth(), pImage->GetHeight());
   CBitmap* pbmpOld = dc.SelectObject(&bitmap);

   Graphics graphics(dc.m_hDC);
   status = graphics.GetLastStatus();
   if(Ok == status)
   {
      graphics.DrawImage(pImage, 0, 0);
      // enjoy of bitmap;
   }
   dc.SelectObject(pbmpOld);
}

Much more easier is if you have Bitmap (Bitmap is derived from Image) that has GetHBITMAP method:

using namespace Gdiplus;
Bitmap* pBitmap = Bitmap::FromFile(L"c:\\test.gif");
Status status = pBitmap->GetLastStatus();
if(Ok == status)
{
   HBITMAP hBitmap = NULL;
   status = pBitmap->GetHBITMAP(Color(0,0,0), &hBitmap);
   if(Ok == status)
   {
      CBitmap bitmap;
      bitmap.Attach(hBitmap);
      // enjoy of bitmap;
   }
}





공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함