Einzelnen Beitrag anzeigen

chrizl08

Registriert seit: 14. Sep 2008
14 Beiträge
 
#1

Scanline Schleife sehr langsam!?

  Alt 15. Sep 2008, 14:07
Hi,
ich habe folgende Funktion um einen bestimmten Farbwert in einem Bitmap zu lokalisieren:

Delphi-Quellcode:
Function FindColor(bmp:TBitmap):TPoint;
type
  PixArray = array[1..3] of Byte;
var
  i, iMax, x, y, w, h: Integer;
  p : ^PixArray;
begin

  Result:=Point(-1,-1);

  Form1.ProgressBar1.Max := bmp.Height-1;

  for y := 0 to bmp.Height-1 do begin
    p := bmp.ScanLine[y];
    Form1.ProgressBar1.Position := y;
    for x := 0 to bmp.Width-1 do begin
      if( (p^[3]=255) AND (p^[2]=0) AND (p^[1]=0) ) then begin
        Showmessage('Gefunden');
        Result := Point(x, y);
        exit;
      end;
    end;
  end;
end;
Das Bitmap wird mit folgendem Code erzeugt:
Delphi-Quellcode:
var DC: HDC;
begin
DC := GetDC(GetDesktopWindow);
bmp:=TBitmap.Create;
try
bmp.Width := GetDeviceCaps(DC, HORZRES);
bmp.Height := GetDeviceCaps(DC, VERTRES);
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width, bmp.Height, DC,0,0,SRCCOPY );
Finally
ReleaseDC(GetDesktopWindow, DC);
end;
end;
Meine Frage nun: Ist es möglich diesen Code zu optimieren (und ich hoffe es ist möglich =) ) und schneller zu machen???

Vielen Dank für Eure Tipps
  Mit Zitat antworten Zitat