贴点代码供你参考:
procedure TimageForm.btnOtherFunctionClick(Sender: TObject);
var
Bmp1,Bmp2 :TBitmap;
i,j :integer;
P1, P2 : PByteArray;
begin
if bIsPhotoContrast =false then //若不是图像对比状态
begin
showMessage('现在不处于图像对比状态,不能进行图像减影');
exit;
end;
Bmp1 :=TBitmap.Create;
Bmp1.Assign(image2.picture.Bitmap);
Bmp2 :=TBitmap.Create;
Bmp2.Assign(image5.picture.Bitmap);
// BitBlt(Bmp2.Canvas.Handle,0,0,Bmp2.Width,Bmp2.Height,Bmp1.Canvas.Handle,0,
// 0,SRCINVERT); //用作异或操作
for J:=0 to Bmp1.Height - 1 do
begin
P1 := Bmp1.ScanLine[J];
P2 := Bmp2.ScanLine[J];
for I:=0 to Bmp1.Width - 1 do
begin
P1[3*I] := P1[3*I] Xor P2[3*I];
P1[3*I+1] := P1[3*I+1] Xor P2[3*I+1];
P1[3*I+2] := P1[3*I+2] Xor P2[3*I+2];
end;
end;
Image5.Picture.Bitmap.Assign(Bmp1);
Bmp1.Free;
Bmp2.Free;
end;