Mega Code Archive

 
Categories / Delphi / Graphic
 

Bmp to ico [icon]

procedure bmp2ico(Image: TImage; FileName: TFilename); var Bmp: TBitmap; Icon: TIcon; ImageList: TImageList; begin Bmp := TBitmap.Create; Icon := TIcon.Create; try Bmp.Assign(Image.Picture); ImageList := TImageList.CreateSize(Bmp.Width, Bmp.Height); try ImageList.AddMasked(Bmp, Bmp.TransparentColor); ImageList.GetIcon(0, Icon); // Save it to a file Icon.SaveToFile(FileName); finally ImageList.Free; end; finally Bmp.Free; Icon.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); begin bmp2ico(Image1, 'c:\test.ico'); end;