Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDC and BItmap question

CDC and BItmap question

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maverick
    wrote on last edited by
    #1

    This code is supposed to draw the bitmap/image to an HDC specified: image->Draw(hdc); This was code was ok, and was drawing on CView::OnDraw() Now I want the image to be drawn as an Icon/Thumbnail to a CListBoxCtrl.. This is my code (this code was taken from the CListImageCtrl article..) I get the HBITMAP retunred from the function, then attach it on a CBitmap and then add the CBItmap, and then the icon is supposed to appear on the ListCtrl.. But it doesn't... the original code is like this: IPicture* pPic; OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic); ... ... ... HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG); CDC hdcSrc, hdcDst; hdcSrc.CreateCompatibleDC(NULL); hdcDst.CreateCompatibleDC(NULL); // Load the bitmaps into memory DC CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn); hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY); pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm); return pOldBitmapImage This code was ok but I modified this code because IPicture cant handle other image formats to i use an image library.. i replace this code: CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); with: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); T The images doesn't appear.. I modified the code based on my understanding of CDC and Bitmaps.. Help please:) "the possibilities are endles..."

    P 1 Reply Last reply
    0
    • M Maverick

      This code is supposed to draw the bitmap/image to an HDC specified: image->Draw(hdc); This was code was ok, and was drawing on CView::OnDraw() Now I want the image to be drawn as an Icon/Thumbnail to a CListBoxCtrl.. This is my code (this code was taken from the CListImageCtrl article..) I get the HBITMAP retunred from the function, then attach it on a CBitmap and then add the CBItmap, and then the icon is supposed to appear on the ListCtrl.. But it doesn't... the original code is like this: IPicture* pPic; OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic); ... ... ... HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG); CDC hdcSrc, hdcDst; hdcSrc.CreateCompatibleDC(NULL); hdcDst.CreateCompatibleDC(NULL); // Load the bitmaps into memory DC CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn); hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY); pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm); return pOldBitmapImage This code was ok but I modified this code because IPicture cant handle other image formats to i use an image library.. i replace this code: CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); with: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); T The images doesn't appear.. I modified the code based on my understanding of CDC and Bitmaps.. Help please:) "the possibilities are endles..."

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      Maverick wrote: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); When you create a DC via CreateCompatibleDC it does not have a usable drawing surface (memory) associated with it. You have to use SelectObject to select a bitmap drawing surface into it. And be sure to restore the DC back to it's original state before deleting it.

      hdcSrc.CreateCompatibleDC(NULL);
      CBitmap TempBitmap;
      TempBitmap.CreateCompatibleBitmap(hdcDst, image->Width(), image->Height());
      CBitmap *pOldBitmap = (CBitmap *)hdcSrc.SelectObject(&TempBitmap);
      image->Draw(hdcSrc.GetSafeHdc());
      ...
      hdcSrc.SelectObject(pOldBitmap); // restore old bitmap


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      M 1 Reply Last reply
      0
      • P PJ Arends

        Maverick wrote: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); When you create a DC via CreateCompatibleDC it does not have a usable drawing surface (memory) associated with it. You have to use SelectObject to select a bitmap drawing surface into it. And be sure to restore the DC back to it's original state before deleting it.

        hdcSrc.CreateCompatibleDC(NULL);
        CBitmap TempBitmap;
        TempBitmap.CreateCompatibleBitmap(hdcDst, image->Width(), image->Height());
        CBitmap *pOldBitmap = (CBitmap *)hdcSrc.SelectObject(&TempBitmap);
        image->Draw(hdcSrc.GetSafeHdc());
        ...
        hdcSrc.SelectObject(pOldBitmap); // restore old bitmap


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

        M Offline
        M Offline
        Maverick
        wrote on last edited by
        #3

        so, meaning before i draw to a CDC, it must have an attached HBITMAP first right? tnx bro.! :) "the possibilities are endless..."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups