遍历象素值的问题~(30分)

L

logpie

Unregistered / Unconfirmed
GUEST, unregistred user!
for y:=0 to image2.Height do
begin
x:=0;
repeat
x:=x+1 ;
r1:= getpixel(image1.Picture.Bitmap.Canvas.Handle,x,y);
r2:= getpixel(image2.Picture.Bitmap.Canvas.Handle,x,y);
if r1 and r2 <> 0 then
memo1.Lines.Add(inttostr(x)+','+inttostr(y));
until x>image2.Width ;
end;
end;
image1和image2图象一样
但为什么memo1显示所有点象素值都不一样?
 
“if r1 and r2 <> 0 then”,r1=r2,当然(r1 and r2)不等于0了,除非r1和r2都是0(纯黑色)
 
r1=r2还是一样
 
if r1<>r2 then ...
这才是找不一样的点!
 
也没有用啊,你试一试,IMAGE1和IMAGE2图象不一样,还是找不出不同点,memo1没结果.
 
绝对不可能,if r1<>r2 then ...,我这里一切正常。
 
晕的了,我刚试的,代码也没问题呀,能看看你是怎么写的吗?
 
你的两个图片到底是一样还是不一样?:(
 
一样和不一样时,MEMO1都没结果
 
procedure TForm1.Button1Click(Sender: TObject);
var
y,x,r1,r2: integer;
begin

for y:=0 to image2.Height do
begin
x:=0;
repeat
x:=x+1 ;
r1:= getpixel(image1.Picture.Bitmap.Canvas.Handle,x,y);
r2:= getpixel(image2.Picture.Bitmap.Canvas.Handle,x,y);
if r1 <> r2 then
memo1.Lines.Add(inttostr(x)+','+inttostr(y));
until x>image2.Width ;
end;

end;

一样时没有结果是对的,如果两图不一样,还没有结果.....,我无话可说了。:)
 
我想唯一的可能是你用的是JPG而非BMP图片!换BMP试试。
 
恩,没错,那JPG要怎么样判断呢?
 
不要转换成BMP的
 
uses clipbrd;

procedure TForm1.Button1Click(Sender: TObject);
var
y,x,r1,r2: integer;
Bitmap1, Bitmap2: TBitmap;
begin

// just for JPG images
Bitmap1 := TBitmap.Create;
Bitmap2 := TBitmap.Create;
Clipboard.Assign(Image1.Picture);
Bitmap1.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
Clipboard.Assign(Image2.Picture);
Bitmap2.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);

for y:=0 to image2.Height do
begin
x:=0;
repeat
x:=x+1 ;
r1:= getpixel(Bitmap1.Canvas.Handle,x,y);
r2:= getpixel(Bitmap2.Canvas.Handle,x,y);
if r1 <> r2 then
memo1.Lines.Add(inttostr(x)+','+inttostr(y));
until x>image2.Width ;
end;
memo1.Lines.Add('end');

Bitmap1.FreeImage;
Bitmap2.FreeImage;

end;
 
接受答案了.
 
顶部