// 装载图像
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
// 将Image1中的内容分解成R,B,G三色,并保存到Res0.bmp, Res1.bmp, Res2.bmp
procedure TForm1.Button1Click(Sender: TObject);
var
bitmap: TBitmap;
fPath: string;
c: TColor;
i, x, y: integer;
begin
// 取原路径
fPath := ExtractFilePath(OpenPictureDialog1.FileName);
// 创建缓冲区
bitmap := TBitmap.Create;
try
with bitmap do
begin
Width := Image1.Picture.Bitmap.Width; // 缓冲区尺寸
Height := Image1.Picture.Bitmap.Height;
for i := 0 to 2 do
begin
for y := 0 to Height - 1 do // 行扫描
for x := 0 to Width - 1 do // 列扫描
begin
// 取原图像颜色
c := Image1.Picture.Bitmap.Canvas.Pixels[x,y];
// 取颜色,并取反
case i of
0: c := RGB(255-GetRValue(c), 0, 0);
1: c := RGB(0, 255-GetGValue(c), 0);
2: c := RGB(0, 0, 255-GetBValue(c));
end;
Canvas.Pixels[x,y] := c; // 写目标
end;
// 保存
SaveToFile(fPath + 'Res'+ IntToStr(i) +'.BMP');
end;
end;
finally
bitmap.Free;
end;
end;