• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
BeyondTechnology
博客园    首页    新随笔    联系   管理    订阅  订阅

How can I convert from GdiPlus::Image to CBitmap?

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

 

Code:
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:
Code:
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;
   }
}
posted @ 2010-11-16 01:04  BeyondTechnology  阅读(2500)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3