VCL 和 Firemonkey 的 Bitmap 處理像素的方式不相同,下例為將圖片內不是「白色」的像素全部改成「黑色」:
procedure TForm1.Button1Click(Sender: TObject);
var x, y: Integer;
vBitMapData: TBitmapData;
begin
if Image1.Bitmap.Map(TMapAccess.maWrite, vBitMapData) then
begin
for x:=0 to Image1.Bitmap.Width - 1 do
for y:=0 to Image1.Bitmap.Height - 1 do
if vBitMapData.GetPixel(x, y) <> TAlphaColors.White then
vBitMapData.SetPixel(x, y, TAlphaColors.Black);
Image1.Bitmap.Unmap(vBitMapData);
end;
end;