问题描述
如何在 Firemonkey 中为 TBitmap 创建校验和? (不是TPicture)。最好直接使用,而不是保存到 Streams。
我对 Map 进行了一些研究,该 Map 取代了 Firemonkey 中的 Scanline... How to access TBitmap pixels directly in FMX2 (TBitmap.ScanLine replacement)?
但还是完全迷失了。有没有人知道如何使用 FMX 扫描线替换来做到这一点?
我看到以下 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;
基本上我只需要检查图像(在内存中)是否已更改(宽度/高度不够,因为即使图像已更改,大多数情况下宽度/高度也不会更改),并且我不想保存到 Streams 中如果我可以对 FMX TBitmap 进行直接校验和,则为哈希。
Qn : 我如何使用下面的代码对等效的扫描线进行校验和?
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;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)