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. How do I 'fill' a CBitmap with a DC's 'image'

How do I 'fill' a CBitmap with a DC's 'image'

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionhelptutorial
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I would like to create a CBitmap object from a DC, then draw the bitmap on each successive repaint rather than doing all the drawing stuff again (there is quite a lot, which is why I want to use this approach). So, I know how to blit the CBitmap back to the DC each time the window is repainted, but I don’t know how to copy the stuff I’ve drawn to the DC into the CBitmap. How would I do this? Thanks in advance for any help you can give me. Yours, James Millson

    L J 2 Replies Last reply
    0
    • L Lost User

      I would like to create a CBitmap object from a DC, then draw the bitmap on each successive repaint rather than doing all the drawing stuff again (there is quite a lot, which is why I want to use this approach). So, I know how to blit the CBitmap back to the DC each time the window is repainted, but I don’t know how to copy the stuff I’ve drawn to the DC into the CBitmap. How would I do this? Thanks in advance for any help you can give me. Yours, James Millson

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Once I've create a function CopyBitmap(..) to copy a bitmap form one to another. Note that it does not work on all kind of bitmaps (eg 32-bits not ). You should be able to find the way to copy the image from your DC to a CBitmap. Hint: iso SourceDC use your own pointer to DC in the function BitBlt(..). Have fun! Kit BOOL CBetterBitmap::CopyBitmap ( CBitmap* pbmpSource, // IN: Source bitmap CBitmap* pbmpDest // OUT: Target bitmap ) { BOOL bResult = FALSE; // Invalid source bitmap ASSERT(pbmpSource != NULL); // pbmpDest must point to an existing CBitmap instance ASSERT(pbmpDest != NULL); ASSERT(pbmpDest->GetSafeHandle() == NULL); // Quick pointer verification if ( (pbmpSource != NULL) && (pbmpDest != NULL) ) { BITMAP bmp; pbmpSource->GetBitmap(&bmp); // First copy the bitmap information if (pbmpDest->CreateBitmapIndirect(&bmp)) { CDC SourceDC; CDC DestDC; // Now copy the bitmap via display compatible DC's if ( (SourceDC.CreateCompatibleDC(NULL) != FALSE) && (DestDC.CreateCompatibleDC(NULL) != FALSE) ) { CBitmap* pbmpPrevSrc = SourceDC.SelectObject(pbmpSource); CBitmap* pbmpPrevDest = DestDC.SelectObject(pbmpDest); bResult = DestDC.BitBlt(0, // Source Left 0, // Source Top bmp.bmWidth, // Source Width bmp.bmHeight, // Source Height &SourceDC, // Source DC 0, // Target Left 0, // Target Top SRCCOPY); // Raster Operation DestDC.SelectObject(pbmpPrevSrc); SourceDC.SelectObject(pbmpPrevDest); } } } // Return result return bResult; }

      1 Reply Last reply
      0
      • L Lost User

        I would like to create a CBitmap object from a DC, then draw the bitmap on each successive repaint rather than doing all the drawing stuff again (there is quite a lot, which is why I want to use this approach). So, I know how to blit the CBitmap back to the DC each time the window is repainted, but I don’t know how to copy the stuff I’ve drawn to the DC into the CBitmap. How would I do this? Thanks in advance for any help you can give me. Yours, James Millson

        J Offline
        J Offline
        Jonathon Lockett
        wrote on last edited by
        #3

        If you've got a DC and you want to copy it to a CBitmap, just select the CBitmap into another DC and Blt across. Jonathon

        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