How should I create colored rectangular areas in a bitmap, please? The speed of execution is important, BTW.
Announcement
Collapse
No announcement yet.
colored rectangular areas in a bitmap - how?
Collapse
X
-
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 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
-
FillRect()Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
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.
Comment
-
Originally posted by Chris Boss View Post"Dirty Rectangles"
**** added - there is a very useful tutorial here: http://www.codeproject.com/KB/GDI/updatergn.aspxLast edited by Chris Holbrook; 11 Feb 2009, 11:50 AM.
Comment
-
see source code forum for implementation of "Dirty Rectangles": http://www.powerbasic.com/support/pb...291#post309291
Comment
Comment