troubleshooting Question

Delphi 7: After many BitBlts to bitmap it doesn't change anymore

Avatar of JackJohnsons
JackJohnsons asked on
DelphiEditors IDEs
12 Comments1 Solution1230 ViewsLast Modified:
Hello experts

I wrote a function to find a color on the screen, it uses bitblt then directly accesses the bitmap in memory. it works fine, but when I call the function in a burst (for i := 0 to 10000 i.e.) the bitmap "hangs". When the screen changes the bitmap doesnt change anymore =/ It's certainly not the way of accessing the bitmap because when I draw the bitmap to another canvas, it reflects the old screen.
Anyone who got an idea why?
unit ColourFinder;
 
{$O+}
 
interface
 
uses Windows, Variants, Graphics, Sysutils, Forms;
 
type
  TRGB24 = packed Record
    b,g,r: Byte;
  end;
 
  TRGB24Array = Array [0..MaxInt div SizeOf(TRGB24)-1] of TRGB24;
  PRGB24Array = ^TRGB24Array;
 
var
  SBMP : TBitmap; //Search bitmap
  Scanlines: Array of PRGB24Array; //scanlines
  I: Integer; //for for loop for getting the scanlines
 
function FindColor(var x, y: Integer; color, xs, ys, xe, ye: Integer; ClientDC : HDC): Boolean;
 
implementation
 
function FindColor(var x, y: Integer; color, xs, ys, xe, ye: Integer; ClientDC : HDC): Boolean;
var
  xx, yy: Integer;
  R, G, B: Byte;
begin
 
  R:= color;
  G:= color shr 8;
  B:= color shr 16;
 
  BitBlt(SBMP.Canvas.Handle, xs, ys, xe - xs, ye - ys, ClientDC, xs, ys, SRCCOPY);
 
  for yy:= ys to ye do
    for xx:= xs to xe do
      if(Scanlines[yy][xx].R = R)then if(Scanlines[yy][xx].G = G)then if(Scanlines[yy][xx].B = B)then
      begin
        x:= xx;
        y:= yy;
        Result:= True;
        exit;
      end;
  Result:= False;
  x:= -1;
  y:= -1;
end;
 
initialization
  SBMP := TBitmap.Create; //Create the search bitmap
  SBMP.Width:= Screen.Width;
  SBMP.Height:= Screen.Height;
  SetLength(Scanlines, SBMP.Height);
  SBMP.PixelFormat:= pf24bit;
  for I:= 0 to SBMP.Height - 1 do
    Scanlines[i]:= SBMP.ScanLine[i];
  ClientDC := GetDC(0);
end.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros