Einzelnen Beitrag anzeigen

Flips

Registriert seit: 17. Feb 2005
Ort: Sankt Wendel
491 Beiträge
 
Delphi 7 Professional
 
#6

Re: Scanline Schleife sehr langsam!?

  Alt 15. Sep 2008, 14:47
Zitat von chrizl08:
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;
Der Code kann auch gar nicht ordentlich funktionieren,
in die innere Schleife muss noch ein inc(p)!


[Edit]
Mit einer Schleife gehts auch, was folglich auch schneller sein sollte (nur als Beispiel):
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
p:^TRGBTriple;
begin
image1.picture.bitmap.PixelFormat := pf24Bit;
with image1.picture.bitmap do
  begin
    p := scanline[height-1];
    for i := 0 to (height*width)-1 do
      begin
        if p^.rgbtRed = $FF then
          ShowMessage('ja');
        inc(p);
      end;
  end;
end;
[/Edit]
Philipp F.
  Mit Zitat antworten Zitat