Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert icon to png with alpha transparency in delphi?

Tags:

delphi

The code below will extract icon from file and convert it to png but without alpha transparency ?

var
   IconIndex : word;
   icon:TIcon;
   png:TPngImage;
   bmp:TBitmap;
begin
  IconIndex := 0;
  icon := TIcon.Create;
  icon.Handle := ExtractAssociatedIcon(hInstance,pChar(Edit1.Text), IconIndex) ;
  bmp:= TBitmap.Create;
  bmp.LoadFromFile('blank.bmp');
  DrawIcon(bmp.Canvas.Handle, 0, 0, icon.Handle) ;
  png := TPngImage.Create();
  png.Assign(bmp);
  png.SaveToFile('icon.png');
end;
like image 372
isa Avatar asked Jul 17 '09 05:07

isa


1 Answers

The PngComponents contain a unit PngFunctions.pas, where you can have a look at

procedure ConvertToPNG(Source: TGraphic; out Dest: TPngImage);

There you can find the code to convert a TIcon into a TPngImage - or just use that procedure.

like image 120
Uwe Raabe Avatar answered Sep 25 '22 17:09

Uwe Raabe