大致是这么个意思 for i := 1 to ABitmap1.Width do begin for j := 1 to ABitmap1.Height do begin if ABitmap1.Canvas.Pixels[i,j] <> ABitmap2.Canvas.Pixels[i,j] begin ShowMessage('no'); Break; end; end; end;
用流把文件打开,循环读一定大小到内存,用CompareMem比较
也许还可以打个相似的分数 for i := 1 to ABitmap1.Width do begin for j := 1 to ABitmap1.Height do begin if ABitmap1.Canvas.Pixels[i,j] <> ABitmap2.Canvas.Pixels[i,j] then n:=n+1 else y:=y+1; end; end; 分数=(y/(y+n))*100;
这是查到的参考代码,大家看看 function IsBmpSame(bmp1,bmp2: TBitmap): Boolean; var i,j: Integer; ScanLine1,ScanLine2: PByteArray; Count: Integer; begin Result := (bmp1.Height = bmp2.Height) and (bmp1.Width = bmp2.Width) and (bmp1.PixelFormat = bmp2.PixelFormat); if Result then begin i := Integer(bmp1.PixelFormat); if i < 4 then i := 4 else if i = 4 then inc(i); Count := (i - 3) * bmp1.Width - 1; for i:=0 to bmp1.Height-1 do begin ScanLine1 := bmp1.ScanLine[i]; ScanLine2 := bmp2.ScanLine[i]; for j := 0 to Count do if ScanLine1[j] <> ScanLine2[j] then begin Result := False; Exit; end; end; end; end; 本文来自Delphi之窗资源分享,原文地址:http://www.52delphi.com
function Compare2Line(pBmpMain,pBmpSub: TBitmap): Boolean; var b: boolean; i,j: integer; ptr1,ptr2: Pointer; begin for i := 0 to pBmpMain.Height - 1 do begin ptr1 := pBmpMain.ScanLine[i]; ptr2 := pBmpSub.ScanLine[i]; b := CompareMem(ptr1,ptr2,pBmpMain.Width * 3); if not b then break; end; Result := b; end;
1.逐点比较,这个是最基础的办法了
2.crc校验
3.如果是两个.bmp文件,不是在delphi中打开的图像,可以参考一下文件比较的方法,crc或md5
如:
var
ACanvas: TControlCanvas;
ABitmap1,ABitmap2: TBitmap;
begin
ABitmap1 := TBitmap.Create;
ABitmap2 := TBitmap.Create; ACanvas := TControlCanvas.Create;
ABitmap1.Width := a_Width;
ABitmap1.Height := a_Height;
ABitmap2.Width := b_Width;
ABitmap2.Height := b_Height;
取得图片
ACanvas.Control := 图片;
ACanvas.Draw(0, 0, ABitmap1);
ACanvas.Draw(0, 0, ABitmap2);
下面如何比较?
。。
begin
for j := 1 to ABitmap1.Height do
begin
if ABitmap1.Canvas.Pixels[i,j] <> ABitmap2.Canvas.Pixels[i,j]
begin
ShowMessage('no');
Break;
end;
end;
end;
begin
for j := 1 to ABitmap1.Height do
begin
if ABitmap1.Canvas.Pixels[i,j] <> ABitmap2.Canvas.Pixels[i,j] then
n:=n+1
else
y:=y+1;
end;
end;
分数=(y/(y+n))*100;
function IsBmpSame(bmp1,bmp2: TBitmap): Boolean;
var
i,j: Integer;
ScanLine1,ScanLine2: PByteArray;
Count: Integer;
begin
Result := (bmp1.Height = bmp2.Height) and
(bmp1.Width = bmp2.Width) and
(bmp1.PixelFormat = bmp2.PixelFormat);
if Result then
begin
i := Integer(bmp1.PixelFormat);
if i < 4 then
i := 4
else if i = 4 then
inc(i);
Count := (i - 3) * bmp1.Width - 1; for i:=0 to bmp1.Height-1 do
begin
ScanLine1 := bmp1.ScanLine[i];
ScanLine2 := bmp2.ScanLine[i];
for j := 0 to Count do
if ScanLine1[j] <> ScanLine2[j] then
begin
Result := False;
Exit;
end;
end;
end;
end;
本文来自Delphi之窗资源分享,原文地址:http://www.52delphi.com
function Compare2Line(pBmpMain,pBmpSub: TBitmap): Boolean;
var
b: boolean;
i,j: integer;
ptr1,ptr2: Pointer;
begin
for i := 0 to pBmpMain.Height - 1 do
begin
ptr1 := pBmpMain.ScanLine[i];
ptr2 := pBmpSub.ScanLine[i];
b := CompareMem(ptr1,ptr2,pBmpMain.Width * 3);
if not b then break;
end;
Result := b;
end;