Extract icon from execute, transparenty\mask problem lazarus / 39-Graphics ---------------------------------------------------------------------- MaartenJB · 2013-02-28 07:43 Hi, I've got some code to extract an icon from an execute. This works okey, but the result is without transparenty\mask. Is there a way to make this work? Thanks Code: [Select]uses ...., LCLType, ShellApi; var   LargeIco, SmallIco : hIcon;   myIcon : TIcon; begin   if ExtractIconEx(PChar('C:\Windows\System32\notepad.exe'), 0, LargeIco, SmallIco, 1) > null then begin     myIcon := TIcon.Create;     try       myIcon.Handle := LargeIco;       myIcon.Transparent := True;       myIcon.SaveToFile('c:\temp\abc.ico');     finally       myIcon.Free;     end;   end; end; ---------------------------------------------------------------------- BigChimp · 2013-02-28 08:28 Have no experience with this but just a hunch: don't you have to set a certain pixel colour to mark transparency? ---------------------------------------------------------------------- MaartenJB · 2013-02-28 08:35 thanks for your hunch, but I think not, the icon contains a mask ---------------------------------------------------------------------- vrull · 2013-03-13 19:49 Just add myIcon.Masked := true; I tried your code as below and it worked fine Code: [Select]...// top if the unit type   TForm1 = class(TForm)     Image1: TImage;     dlgOpen: TOpenDialog;     procedure Image1DblClick(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation    uses LCLType, ShellApi; {$R *.lfm} { TForm1 } procedure TForm1.Image1DblClick(Sender: TObject); var   LargeIco, SmallIco : hIcon;   myIcon : TIcon; begin   if dlgOpen.Execute then     if ExtractIconEx(PChar(dlgOpen.FileName), 0, LargeIco, SmallIco, 1) > null then       begin         myIcon := TIcon.Create;         try           myIcon.Transparent := True;           myIcon.Masked := True;           myIcon.Handle := LargeIco;           Image1.Picture.Icon.Assign(myIcon);         finally           myIcon.Free;         end;     end; end; ---------------------------------------------------------------------- MaartenJB · 2013-03-14 09:08 Hi, Thanks for your reply. I've tried that, the "masked" option does not change anything if I try it. I've made a screenshot of the result I got, the left icon is the one I extracted with an other application and the right one is extracted with the code above. so there is a big difference in icon quality, do you get a better result? ---------------------------------------------------------------------- vrull · 2013-03-14 19:19 I've made some investigation and found that the problem is not in the ExtractIconEx function, which works just fine, but in further manipulation with the icon handler. The attached project proves, that if one draws the icons straight away their quality is not deteriorated (double-click on the second image). So you should find the way to turn icon handle into something more familiar without damaging the underlying image. ---------------------------------------------------------------------- MaartenJB · 2013-03-15 08:39 That's looking very promising. Thank you very much!  So the problem is withing TIcon. I'll try to find a way to get around it.