给你一个过程,其将小图放在与ImageList大小一样的画布的中央,然后加入。其实,静态加入时就采取了类似的方法。
procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap1, Bitmap2: TBitmap;
Rect: TRect;
begin
Bitmap1 := TBitmap.Create;
Bitmap2 := TBitmap.Create;
Bitmap1.Transparent := true;
Bitmap1.TransparentColor := clNone;
Bitmap2.Transparent := true;
Bitmap2.TransparentColor := clNone;
Bitmap2.Height := ImageList1.Height;
Bitmap2.Width := ImageList1.Width;
Bitmap1.LoadFromFile('C:/My Documents/My Pictures/图标/Bitmap3.bmp');
Rect := Bitmap1.Canvas.ClipRect;
Rect.Left := (Bitmap2.Width - Bitmap1.Width) div 2 - Rect.Left;
Rect.Top := (Bitmap2.Height - Bitmap1.Height)div 2 - Rect.Top;
Rect.Right := (Bitmap2.Width - Bitmap1.Width)div 2 + Rect.Right;
Rect.Bottom := (Bitmap2.Height - Bitmap1.Height)div 2 + Rect.Bottom;
Bitmap2.Canvas.CopyRect(Rect, Bitmap1.Canvas, Bitmap1.Canvas.ClipRect);
ImageList1.Add(Bitmap2, nil);
Bitmap1.Free;
Bitmap2.Free;
end;