2个图片,用SCANLINE 如何比较不同?
解决方案 »
- dbgrid 数据库 关系问题
- dephi l联合定义
- 点数< 5 ,两层(c/s) 用Access 库有问题吗?
- ADO的事务操作(BeginTrans、CommitTrans、RollbackTrans)在删除操作(Delete)时为什么会发生意外?
- 简单的数据库问题对菜鸟也很难,请大侠来帮我
- pagecontrol控件的用法!(100分)
- 关于Installshield(我在Installshield6.2中安装,能创建快捷方式,可是在7.0中创建不了呀!!)
- 我正在翻译<mastering delphi 6>,已经翻译完第一部分第一章第一节,第二节马上完成,可以去我的网站下载。www.allexit.info (一个很烂
- 请问在线程HOOK的回调函数中, 如何拦截自定义消息
- 关于 Delphi 6.0 的盗版光盘!
- delphi队列使用问题
- dspack如何设置摄像头视频质量
google搜索出来的。网上貌似很多
如果想对文件比较,一般是先散列生成摘要,然后对摘要进行比较
可以去看看《Delphi数字图像处理及高级应用》
procedure TForm1.Button1Click(Sender: TObject);
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
var
x,y:integer;
p0,p1: PRGBTripleArray;
begin
Image1.Picture.LoadFromFile('C:\WINNT\wallpaper.bmp');
Image2.Picture.LoadFromFile('C:\WINNT\wallpaper1.bmp'); if (Image1.Picture.Bitmap.Height<>Image2.Picture.Bitmap.Height)or
(Image1.Picture.Bitmap.Width <>Image2.Picture.Bitmap.Width ) then
begin
caption:='不同';
Exit;
end; Image1.Picture.Bitmap.PixelFormat :=pf24bit;
Image2.Picture.Bitmap.PixelFormat :=pf24bit;
for y:=0 to Image1.Picture.Bitmap.Height -1 do
begin
p0:=Image1.Picture.Bitmap.ScanLine[y];
p1:=Image2.Picture.Bitmap.ScanLine[y];
for x:=0 to Image1.Picture.Bitmap.Width -1 do
if (p0[x].rgbtBlue =p1[x].rgbtBlue)and
(p0[x].rgbtGreen =p1[x].rgbtGreen )and
(p0[x].rgbtRed =p1[x].rgbtRed ) then
begin
caption:='相同';
end
else
begin
caption:='不同';
Exit;
end; end;end;//方法2
function IsHomology(bmp1, bmp2: TbitMap): boolean;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
var
x, y: integer;
p0, p1: PRGBTripleArray;
sBmp, dBmp: TBitMap;
begin
Result := False; if (bmp1.Height <> bmp2.Height) or
(bmp1.Width <> bmp2.Width) then
begin
Exit;
end; sBmp := TBitmap.Create;
dBmp := TBitmap.Create;
try
sBmp.Assign(bmp1);
dBmp.Assign(bmp2);
sBmp.PixelFormat := pf24bit;
dBmp.PixelFormat := pf24bit;
for y := 0 to sBmp.Height - 1 do
begin
p0 := sBmp.ScanLine[y];
p1 := dBmp.ScanLine[y];
for x := 0 to sBmp.Width - 1 do
if (p0[x].rgbtBlue = p1[x].rgbtBlue) and
(p0[x].rgbtGreen = p1[x].rgbtGreen) and
(p0[x].rgbtRed = p1[x].rgbtRed) then
begin
Result := True;
end
else
begin
Break;
end;
end;
finally
sBmp.Free;
dBmp.Free;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if IsHomology(SpeedButton1.Glyph, SpeedButton2.Glyph) then
showmessage('相同');
end;
//**********************************************
//方法3 比较,并将不同的复制
//**********************************************
function IsHomology(bmp1, bmp2: TbitMap): boolean;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
var
x, y: integer;
p0, p1: PRGBTripleArray;
sBmp, dBmp: TBitMap;
begin
Result := True; if (bmp1.Height <> bmp2.Height) or
(bmp1.Width <> bmp2.Width) then
begin
Exit;
end; sBmp := TBitmap.Create;
dBmp := TBitmap.Create;
try
sBmp.Assign(bmp1);
dBmp.Assign(bmp2);
sBmp.PixelFormat := pf24bit;
dBmp.PixelFormat := pf24bit;
for y := 0 to sBmp.Height - 1 do
begin
p0 := sBmp.ScanLine[y];
p1 := dBmp.ScanLine[y];
for x := 0 to sBmp.Width - 1 do
if (p0[x].rgbtBlue = p1[x].rgbtBlue) and
(p0[x].rgbtGreen = p1[x].rgbtGreen) and
(p0[x].rgbtRed = p1[x].rgbtRed) then
begin
// Result := True;
end
else
begin
Result := False;
p1[x] := p0[x];
end;
end;
Bmp2.Assign(dBmp);
finally
sBmp.Free;
dBmp.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
IsHomology(Image2.Picture.Bitmap, Image1.Picture.Bitmap);
end;
begin
if (p0[x].rgbtBlue = p1[x].rgbtBlue) and (p0[x].rgbtGreen = p1[x].rgbtGreen) and (p0[x].rgbtRed = p1[x].rgbtRed) then //不管这三个比较的结果相等不相等,光标运行到这的时候跳到★
begin
Result := True;
end else
begin
Break; //1
end;
end;//★
end;
应该是不同时跳到1,相同时跳到2的吧?怎么跑出去了?