terça-feira, 14 de fevereiro de 2012

Delphi - Criando uma Procedure para transformar BMP em ÍCONE


procedure Tform1.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;

Para chamá-la utiliza um botão, segue abaixo o código.

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
   bmp2ico(Image1, 'c:\Teste\icone.ico');
end;

Nenhum comentário:

Postar um comentário