delphi - Firemonkey中TBitmap的校验和
问题描述
如何在 Firemonkey 中为 TBitmap 创建校验和?(不是 TPicture)。最好直接,而不是保存到 Streams。
我已经对在 Firemonkey 中替换 Scanline 的 Map 进行了一些研究...... 如何直接在 FMX2 中访问 TBitmap 像素(TBitmap.ScanLine 替换)?
但仍然完全迷失了。有谁知道如何使用 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;
基本上我只需要检查图像(在内存中)是否已经改变(宽度/高度不够,因为大多数时候宽度/高度不会改变,即使图像已经改变),如果我可以对 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;
解决方案
推荐阅读
- dart - BottomAppBar 中缺少停靠的 FloatingActionButton 的缺口
- eclipse - 我可以以编程方式指定 Eclipse RCP 编辑器部件的大小吗?
- asp.net-web-api2 - 可选参数的空值 ASP.NET Web API
- inno-setup - Inno Setup:如何使用用户输入有条件地执行代码
- java - 收到错误 javaFX
- php - 为什么我网站的所有子路径都找不到 404?
- sql - 当所有值都为 NULL 时不返回行 - SQL
- email - 从命令行 ubuntu 发送邮件
- javascript - 无法滚动javascript
- java - 如何在 CompletableFuture.get() 调用上引发异常?