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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how can I clear overlay after using transparentblt

how can I clear overlay after using transparentblt

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 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.
  • G Offline
    G Offline
    gurucplusplus
    wrote on last edited by
    #1

    I use transparentblt to display an overlay color image? ::TransparentBlt(pDC->GetSafeHdc(),upperLeftX, upperLeftY, width, height, paintMemory.GetSafeHdc(),0,0,width,height,RGB(0,0,0)) ; where paintMemory is contains color pixels using method call paintMemory.SetPixel(CPoint(x,y),RGB(255,0,0); the color image is display correctly. How can I clear this overlay?

    M 1 Reply Last reply
    0
    • G gurucplusplus

      I use transparentblt to display an overlay color image? ::TransparentBlt(pDC->GetSafeHdc(),upperLeftX, upperLeftY, width, height, paintMemory.GetSafeHdc(),0,0,width,height,RGB(0,0,0)) ; where paintMemory is contains color pixels using method call paintMemory.SetPixel(CPoint(x,y),RGB(255,0,0); the color image is display correctly. How can I clear this overlay?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      gurucplusplus wrote:

      How can I clear this overlay?

      Draw something else over the top of it? I'm curious why you use the CDC class but you go through the extra trouble of extracting the HDCs from the CDC objects to call a GDI API directly instead of using the CDC method CDC::TrasparentBlt()...? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      G 1 Reply Last reply
      0
      • M Mark Salsbery

        gurucplusplus wrote:

        How can I clear this overlay?

        Draw something else over the top of it? I'm curious why you use the CDC class but you go through the extra trouble of extracting the HDCs from the CDC objects to call a GDI API directly instead of using the CDC method CDC::TrasparentBlt()...? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        G Offline
        G Offline
        gurucplusplus
        wrote on last edited by
        #3

        I am not sure what you mean? Can you give me an example?

        M 1 Reply Last reply
        0
        • G gurucplusplus

          I am not sure what you mean? Can you give me an example?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          It depends on what you mean by "clear this overlay" For the TransparentBlt call... ::TransparentBlt(pDC->GetSafeHdc(),upperLeftX,upperLeftY, width, height,                        paintMemory.GetSafeHdc(),0,0,width,height,RGB(0,0,0)) ; could be pDC->TransparentBlt(upperLeftX, upperLeftY, width, height,                              &paintMemory,0,0,width,height,RGB(0,0,0)) ; Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          G 1 Reply Last reply
          0
          • M Mark Salsbery

            It depends on what you mean by "clear this overlay" For the TransparentBlt call... ::TransparentBlt(pDC->GetSafeHdc(),upperLeftX,upperLeftY, width, height,                        paintMemory.GetSafeHdc(),0,0,width,height,RGB(0,0,0)) ; could be pDC->TransparentBlt(upperLeftX, upperLeftY, width, height,                              &paintMemory,0,0,width,height,RGB(0,0,0)) ; Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            G Offline
            G Offline
            gurucplusplus
            wrote on last edited by
            #5

            For my application, I display paintMemory using ::transparentBlt in red using paintMemory.SetPixel(point(x,y),RGB(255,0,0)) But I don't know how to clear this paintMemory to transparency by reseting paintMemory.SetPixel(point(x,y),RGB(0,0,0)). I have an greyimage display in the background and would like to paint an color image using paintMemory to paint a color on top of this image without destructing the content of the greyimage. Once I draw complete I would like to see this greyimage background back by clearing the painMemory by setting color of paintMemory pixel back to color RGB(0,0,0). But It doesn't work.

            M 1 Reply Last reply
            0
            • G gurucplusplus

              For my application, I display paintMemory using ::transparentBlt in red using paintMemory.SetPixel(point(x,y),RGB(255,0,0)) But I don't know how to clear this paintMemory to transparency by reseting paintMemory.SetPixel(point(x,y),RGB(0,0,0)). I have an greyimage display in the background and would like to paint an color image using paintMemory to paint a color on top of this image without destructing the content of the greyimage. Once I draw complete I would like to see this greyimage background back by clearing the painMemory by setting color of paintMemory pixel back to color RGB(0,0,0). But It doesn't work.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              gurucplusplus wrote:

              But I don't know how to clear this paintMemory to transparency by reseting paintMemory.SetPixel(point(x,y),RGB(0,0,0)).

              paintMemory is a memory DC, correct? An easier and possibly faster way to clear the entire bitmap associated with the DC is something like:    paintMemory.FillSolidRect(0, 0, BitmapWidth, BitmapHeight(), RGB(0, 0, 0)); What's not working? Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              G 1 Reply Last reply
              0
              • M Mark Salsbery

                gurucplusplus wrote:

                But I don't know how to clear this paintMemory to transparency by reseting paintMemory.SetPixel(point(x,y),RGB(0,0,0)).

                paintMemory is a memory DC, correct? An easier and possibly faster way to clear the entire bitmap associated with the DC is something like:    paintMemory.FillSolidRect(0, 0, BitmapWidth, BitmapHeight(), RGB(0, 0, 0)); What's not working? Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                G Offline
                G Offline
                gurucplusplus
                wrote on last edited by
                #7

                paintMemory is a memory DC. Let do an example. I implement the following: painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(255,0,0)); ::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight, paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0)); // At this point I see the overlay image is red. // Then next is try to clear this overlay painMemory from red to RGB(0,0,0) painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(0,0,0)); ::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight, paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0)); // At this point I still see the overly image is red instead of black I need solution for this ASAP. Thanks

                M 1 Reply Last reply
                0
                • G gurucplusplus

                  paintMemory is a memory DC. Let do an example. I implement the following: painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(255,0,0)); ::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight, paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0)); // At this point I see the overlay image is red. // Then next is try to clear this overlay painMemory from red to RGB(0,0,0) painMemory.FillSolidRect(0,0,BitmapWidth,BitmapHeight(),RGB(0,0,0)); ::TransparentBlt(pDC->GetSafeHdc(),m_upperLeftX, 0,BitmapWidth,0,BitmapHeight, paintMemory.GetSafeHdc(),0,0,BitmapWidth,BitmapHeight,RGB(0,0,0)); // At this point I still see the overly image is red instead of black I need solution for this ASAP. Thanks

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  Are you drawing to the screen?  Is this code in a WM_PAINT message handler (OnPaint())? You can't erase - you need to redraw what was "underneath" the red. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  G 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Are you drawing to the screen?  Is this code in a WM_PAINT message handler (OnPaint())? You can't erase - you need to redraw what was "underneath" the red. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    G Offline
                    G Offline
                    gurucplusplus
                    wrote on last edited by
                    #9

                    Yes, I draw to the screen. I add WM_PAINT message handler OnPaint() as you suggested as shown CMyView::OnPaint() { CPaintDC dc(this); // device context for painting OnPrepareDC(&dc); OnDraw(&dc); } And OnDraw(CDC pDC) I have GDI method to draw image on screen that always works. After I implement OnPaint(). It still doesn't redraw image underneath the red. Please Help!

                    M 1 Reply Last reply
                    0
                    • G gurucplusplus

                      Yes, I draw to the screen. I add WM_PAINT message handler OnPaint() as you suggested as shown CMyView::OnPaint() { CPaintDC dc(this); // device context for painting OnPrepareDC(&dc); OnDraw(&dc); } And OnDraw(CDC pDC) I have GDI method to draw image on screen that always works. After I implement OnPaint(). It still doesn't redraw image underneath the red. Please Help!

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      I didn't suggest anything - I was asking. You don't need an OnPaint override in a view since there's OnDraw(). You do, however, need to draw whatever you want to appear. You can't draw something to the screen and then erase it, expecting to see what was underneath it. It's up to you to redraw the window without the overlay. You can force a window to repaint by invalidating a portion (or all) of the window with one of the Invalidate___() methods/APIs. That will cause your OnDraw() to be called, where you can draw whatever you want to appear on the window. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      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