Announcement

Collapse
No announcement yet.

colored rectangular areas in a bitmap - how?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • colored rectangular areas in a bitmap - how?

    How should I create colored rectangular areas in a bitmap, please? The speed of execution is important, BTW.

  • #2
    Chris,
    use GRAPHIC BOX?
    Code:
    'PBCC5 program
    #BREAK ON
    FUNCTION PBMAIN () AS LONG
    GRAPHIC WINDOW "Rectangles",1,1,400,400 TO hWin???
    GRAPHIC ATTACH hWin???,0
    
    FOR r&=1 TO 200 STEP 5
        FillColour&=r&*2+256
        GRAPHIC BOX (r&*2,r&*3) - (r&*4,r&*5) ,,%RED,FillColour&
    NEXT
              
    WAITKEY$
    
    END FUNCTION
    Paul.

    Comment


    • #3
      So far...

      This code draws a box with the specified line and fill colors on a DC - a memory DC in the application, then triggers WM_PAINT in the target control, and WM_PAINT does the rest. Can it be done better/faster?

      Code:
      '---------------------------------------------------------------------
      sub MyDrawBox ( hDC as dword,  lX as long, lY as long, lW as long, lH as long, lBoxColor as long, lBGColor as long)
          local hOldPen, holdBrush, hbrush as dword
          local r as rect
          
          holdbrush = selectobject(hdc, CreateSolidBrush(lBGColor))
          setrect byval varptr(r), lX, lY, lX + lW, lY + lH
          hOldPen   = SelectObject(hDC, CreatePen(%PS_SOLID, 1, lBoxColor))
          rectangle hDC, lX, lY, lX + lW, lY + lH
          DeleteObject SelectObject(hDC, hOldPen)
          DeleteObject selectobject(hdc, holdbrush)
          invalidaterect ghStatic, byval varptr(r), 1
      end sub
      '-------------------------------------------------------------------------
      (wndproc)
      ....
              case %wm_paint
                  hDC = BeginPaint(ghStatic, PS)
                  bitblt HDC, 0, 0, PS.rcPaint.nright - PS.rcPaint.nleft, _
                                    PS.rcPaint.nbottom - PS.rcPaint.ntop, gHCDC, 0, 0, %SRCCOPY
                  endpaint ghStatic, ps
      *** later: changed first two coordiante parameters in Bitblt for PS.rcPaint.nleft, PS.rcPaint.ntop and it made no difference at all. Does this mean that the PS.rcPaint rect is the same as the whole client rect, even though I only invalidated a little bit of it?

      *** later yet: yes, the whole of the client gets invalidated. Why? How to code around this - a global changedrect?
      Last edited by Chris Holbrook; 11 Feb 2009, 05:56 AM.

      Comment


      • #4
        Originally posted by Paul Dixon View Post
        use GRAPHIC BOX?
        fonely. I'm doing it to replace GRAPHIC BOX, which mixes but poorly with subclassing.

        Comment


        • #5
          FillRect()
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            The solution is a technique called "Dirty Rectangles"!

            When only small portions of the screen are being updated quickly, you can define a region (multiple rectangles combined) which contains only the area which needs to be repainted.

            Create a region and then add every area you plan to update (you draw on) to the region to create a complex region.

            Then call InvalidateRgn to make windows repaint only that region.

            Using dirty rectangles can increase the update speed significantly depending upon how much area is being updated.
            Last edited by Chris Boss; 11 Feb 2009, 09:22 AM.
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Originally posted by Chris Boss View Post
              "Dirty Rectangles"
              Thanks Chris, I am investigating. It is much faster.

              **** added - there is a very useful tutorial here: http://www.codeproject.com/KB/GDI/updatergn.aspx
              Last edited by Chris Holbrook; 11 Feb 2009, 11:50 AM.

              Comment


              • #8
                see source code forum for implementation of "Dirty Rectangles": http://www.powerbasic.com/support/pb...291#post309291

                Comment

                Working...
                X