zoukankan      html  css  js  c++  java
  • 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;
       }
    }
  • 相关阅读:
    封装/继承
    模板
    常用模块-re模块1
    包常用模块
    模块和软件开发的目录规范
    Hadoop 综合大作业
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
  • 原文地址:https://www.cnblogs.com/BeyondTechnology/p/1878102.html
Copyright © 2011-2022 走看看