Thema: Delphi zwei Bitmaps vergleichen

Einzelnen Beitrag anzeigen

Benutzerbild von KahPee
KahPee

Registriert seit: 12. Mai 2009
214 Beiträge
 
Turbo Delphi für Win32
 
#17

Re: zwei Bitmaps vergleichen

  Alt 1. Feb 2010, 22:28
So ich habe das ganze nochmal eingehender studiert. Unten habe ich meine ursprüngliche Funktion noch mal aufgegriffen und versucht anzupassen. Allerdings will das nocht nicht so wie ich will . Wie gebe ich die x-koordinate für den Pixel an? Mein Gefühl sagt, mir das ich nur 2-3 Zeilen von der Lösung weg bin. Aber ich hoffe ich täusche micht nicht . Es wäre nett wenn mir da nochmal auf die Sprünge geholfen werden könnte.

Delphi-Quellcode:
function Bitmapcompare(pic1, pic2: Tbitmap; Posx,posy: Integer): Boolean;
var
  Pix1, Pix2 : PByte;
  y, k, x : Integer;
  bytes : Byte;
  compix, matchpix: integer;
const
  PixelFormatBytes: Array[TPixelFormat] of Byte = ( 0, 0, 0, 1, 0, 2, 3, 4, 0 );
begin
  result:=false;
  bytes1 := PixelFormatBytes[pic1.PixelFormat];
  bytes2 := PixelFormatBytes[pic2.PixelFormat];
  
  if (bytes1 = 0) or (bytes2=0) then
    Exit; // PixelFormat wird nicht unterstützt ... kannst du dann gerne von mir aus umändern ...
  for y := 0 to pic2.Height - 1 do
  begin
    Pix1 := pic1.Scanline[posy+y];
    Pix2 := pic2.Scanline[y];
    for x := 0 to pic2.Width - 1 do
      for k := 0 to bytes2 - 1 do
      begin
    //VERGLEICH
        if pix1=pix2 then inc(matchpix); //x-Koordinate nicht berücksichtigt
    
        Pix1^ := 0;
        inc(Pix1);
        Pix2^ :=0;
        inc(pix2);
      
        inc(compix);
      end;
  end;

   if compix=matchpix then Result:=true;
end;
Übrigens vielen Dank für den Hinweis mit "Inc()", das dürfte mir in Zukunft ein wenig Tipparbeit ersparen

schon mal Vielen Dank

KahPee
  Mit Zitat antworten Zitat