[solved]Loading Icon at run time lazarus / 31-LCL ---------------------------------------------------------------------- dbannon · 2019-12-29 02:33 I want to load a (SystemTray) icon at runtime, someone has made me a nice set of icons for my app and diferent platforms/themes really require a different icon. If I convert my PNG files to ICO, it all works but ICO files are big and as I will be shipping several I would rather ship PNG, they are a tenth of the size. I tried - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.LoadAltIcon();var    AImage : TImage;begin    AImage := TImage.Create(self);    AImage.Picture.LoadFromFile('tomboy24Colour.png');    TrayIcon1.Icon.Assign(AImage.Picture.Bitmap);end;       And, while it worked, it changed the colour of my icon, clearly I am not using the graphics as I should. How should I load a PNG into a Icon ? Davo ---------------------------------------------------------------------- GAN · 2019-12-29 02:59 Yes, I use PNG. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TrayIcon1.Icon.LoadFromFile(); ---------------------------------------------------------------------- dbannon · 2019-12-29 03:35 Quote from: GAN on December 29, 2019, 03:59:47 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TrayIcon1.Icon.LoadFromFile();Yes, thanks GAN, but I had tried that but get an exception : EInvalidGraphic exception, "Stream is not a an Icon Type" I have tried a couple of different PNG files too..... The docs say an incorrect file format will raise an exception but does not tell us just what is an acceptable format. Davo ---------------------------------------------------------------------- lainz · 2019-12-29 03:49 Here is a lot of code with tray icons even with  animation https://github.com/Arandusoft/fpcpaymowidget/blob/master/umain.pas If I remember correctly we're using TImageList... ---------------------------------------------------------------------- dbannon · 2019-12-29 04:00 While thanks are due to Gan and Iainz, I have just realized I am being quite silly. The Lazarus icn file is big (137K) but my 24x24 system tray icon, converted to an ICO file, is tiny, some 2.5K so its not worth worrying about. I'll just ship a few ico files and stop fussing.  Hmm, but some neat tricks in Iainz's link !   Worth some close study ..... Davo ---------------------------------------------------------------------- GAN · 2019-12-29 04:56 Sorry @dbannon you are right, I can use a PNG only from the OI but at runtime get an exception: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomIcon.ReadStream(AStream: TMemoryStream; ASize: Longint);...  if (Header.idType <> 1) and (Header.idType <> 2)  then raise EInvalidGraphic.Create('Stream is not an Icon type');   Bug? ---------------------------------------------------------------------- dbannon · 2019-12-29 06:46 I am not sure I'd label it a bug, its just that it does not do it.  In the ide there is extra code behind the 'Load' button. I guess if I am the first person to expect the same code at run time, its not really needed .... Thanks, Davo