//针对24位真彩图
var
bit :TBitmap;
FColor :TColor;//要替换掉的颜色
ForeColor :TColor;//换成的颜色
r,g,b :Byte;
I,J :Integer;
P ByteArray;
begin
bit :=TBitmap.Create;
bit.Assign(MainImage.Picture.Bitmap);
FColor :=MainImage.Canvas.Pixels[x,y];
r :=GetRValue(FColor);
g :=GetGValue(FColor);
b :=GetBValue(FColor);
for J :=0 to bit.Height-1 do
begin
p :=bit.ScanLine[J];
for I :=0 to bit.Width-1 do
begin
if (p[3*I+2]=r) and (p[3*I+1]=g) and (p[3*I]=b) then
begin
p[3*I+2] :=GetRValue(ForeColor);
p[3*I+1] :=GetGValue(ForeColor);
p[3*I] :=GetBValue(ForeColor);
end;
end;
end;
MainImage.Picture.Bitmap.Assign(bit);
bit.Free;
end;