Einzelnen Beitrag anzeigen

Benutzerbild von Jazzman_Marburg
Jazzman_Marburg

Registriert seit: 2. Aug 2004
359 Beiträge
 
#1

Pixel zählen mit Scanline

  Alt 4. Mai 2012, 20:09
Hallo Gemeinde,
ich versuche gerade alle schwarzen Pixel in einem Image (TImage) zu zählen. Mit Canvas.Pixels geht es wohl -- nur eben langsam. Deswegen versuche ich auf ScanLine umzustellen, und das geht nun gründlich schief. Habe mir diverse Tutorials angeschaut und war meiner Sache sicher -- aber mit ScanLine zähle ich wohl etwas anderes. Deswegen meine Frage/Bitte ob jemand wohl den Fehler sieht?

Delphi-Quellcode:
 type
    TIntegerArray = array[0..MaxInt div SizeOf(integer) - 1] of integer;
    PIntegerArray = ^TIntegerArray;
  ...

 
  Anzahl := 0;
  Anzahl2 := 0;

  k:= myImage.Width;
  l:= myImage.Height;

  { Canvas.Pixels Version ------------------------------------- }
  for x := 0 to k - 1 do
  begin

    for y := 0 to l - 1 do
    begin

      color := myImage.Canvas.Pixels[ x, y ];
      if color = clBlack then
        inc(Anzahl);

    end;

  end;

  { ScanLine Version ------------------------------------------- }
  for y := 0 to l - 1 do
  begin

    ScanLine := myImage.Picture.Bitmap.ScanLine[ y ];
    for x := 0 to k - 1 do
    begin
      
      ScanLine^[x] := color;
      color := BGRToColor( color );
      if color = ClBlack then
        inc( Anzahl2 );

    end;

  end;
  
function BGRToColor(const BGR : Integer) : TColor;
begin
 result := (BGR and $FF000000) + ((BGR and $000000FF) shl 16) + (BGR and $0000FF00) + ((BGR and $00FF0000) shr 16);
end;
Eine Idee, weshalb das Scanline z.B. 489202 für Anzahl2 liefert -- Canvas.Pixels hingegen 5450 (was wohl richtiger ist)?

Vielen Dank
Gruß
Jazzman
--- Delphi XE Starter, Windows 8 ---
  Mit Zitat antworten Zitat