让我给你一个圆满的答复:
procedure TForm1.Monochrome(Icon: TIcon);
var
Bitmap, Mask: TBitmap;
x, y: integer;
Color: Longint;
R, G, B, Gr: byte;
ImageList: TImageList;
begin
Bitmap := TBitmap.Create;
Mask := TBitmap.Create;
ImageList := TImageList.CreateSize(32, 32);
ImageList.AddIcon(Icon);
ImageList.GetBitmap(0, Bitmap);//以上三行实现Ico到Bitmap的转换
with Bitmap.Canvas do
for x := Cliprect.Left to Cliprect.Right do
for y := Cliprect.Top to Cliprect.Bottom do
begin
Color := ColorToRGB(Pixels[x, y]);
B := (Color and $FF0000) shr 16;
G := (Color and $FF00) shr 8;
R := (Color and $FF);
Gr := Trunc(R*0.19 + G*0.44 + B*0.37);
Pixels[x, y] := Gr shl 16 or Gr shl 8 or Gr;
end;//以上实现黑白图象
Mask.Assign(Bitmap);
Mask.Mask(clWhite);//为透明图象设置掩码位图
ImageList.Height := Bitmap.Height;
ImageList.Width := Bitmap.Width;
ImageList.Clear;
ImageList.Add(Bitmap, Mask);
ImageList.GetIcon(0, Icon);//以上实现Bitmap到Ico的转换
ImageList.Free;
Bitmap.Free;
Mask.Free;
end;