How do I create a checksum for TBitmap in Firemonkey? (not TPicture). Preferably directly, and not saving to Streams.
I've done some research on Map that replaces Scanline in Firemonkey... How to access TBitmap pixels directly in FMX2 (TBitmap.ScanLine replacement)?
but still completely lost. Does anyone have an idea how to use the FMX scanline replacement to do this?
I saw below code for VCL :
Function Checksum_CountryFlag(Img : TPicture):Integer;
var j, k, Checksum : Integer;
Line: PIntegerArray;
Pixel : integer;
begin
Checksum := 0;
Img.Bitmap.PixelFormat:= pf32bit; // just for case
For k := 0 to Img.Height - 1 do begin // !! Height first, -1
Line:= Img.Bitmap.ScanLine[k];
For j := 0 to Img.Width - 1 do begin // !! -1
Pixel := Line^[j];
If ((Pixel <> 15577344) And (Pixel <> 15311104) And (Pixel <> 3816255)
And (Pixel <> 10526623) And (Pixel <> 12303034) And (Pixel <> 9013641)) Then
begin
Checksum := Checksum + Pixel;
end;
Inc(Line);
end;
end;
Result := Abs(Checksum);
end;
Basically I just need to check if image (in memory) has changed (Width/Height not sufficient as most times the Width/Height do not change even if image has changed), and I prefer not to save to Streams to do a Hash if I can do a direct checksum on FMX TBitmap.
Qn : How do I use the below code to do a checksum on the scanline equivalent?
procedure TForm1.btnCompareClick(Sender: TObject);
var
bd1, bd2 : TBitmapData;
w,h : Integer;
begin
Image1.Bitmap.LoadFromFile('c:\1.jpg');
Image2.Bitmap.LoadFromFile('c:\2.jpg');
w := Image1.Bitmap.Width;
h := Image1.Bitmap.Height;
try
Image1.Bitmap.Map(TMapAccess.Read, bd1);
Image2.Bitmap.Map(TMapAccess.Write, bd2);
AlphaColorToScanline(@PAlphaColorArray(bd1.Data)[0], bd2.Data,
Round(w * h), Image1.Bitmap.PixelFormat);
finally
Image1.Bitmap.Unmap(bd1);
Image2.Bitmap.Unmap(bd2);
end;
end;