SOLVED: Converting Icon to PNG lazarus / 39-Graphics ---------------------------------------------------------------------- SaraT · 2020-02-15 22:27 Hi friends How can I convert/save the loaded icon from Image1 into PNG with transparency? I will be so grateful for any code provided... Many, many thanks 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 Image1.Picture.LoadFromFile('C:\MyFolder\MyIcon.ico'); ---------------------------------------------------------------------- winni · 2020-02-15 22:51 Hi ! Try this: 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.Button3Click(Sender: TObject);var PNG : TPortableNetworkGraphic;    R : TREct;begin Image2.Picture.LoadFromFile('TuxMon.ico'); PNG := TPortableNetworkGraphic.create; PNG.SetSize (Image2.Width, Image2.Height); R := Rect(0,0,Image2.Width, Image2.Height); PNG.Canvas.CopyRect(R,Image2.Picture.Icon.Canvas, R); PNG. SavetoFile('TuxTest.png'); PNG.Free;end;                         And when do you sleep? All day on the forum and coding .... Winni ---------------------------------------------------------------------- SaraT · 2020-02-15 23:07 Quote from: winni on February 15, 2020, 11:51:34 pmHi ! Try this: 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.Button3Click(Sender: TObject);var PNG : TPortableNetworkGraphic;    R : TREct;begin Image2.Picture.LoadFromFile('TuxMon.ico'); PNG := TPortableNetworkGraphic.create; PNG.SetSize (Image2.Width, Image2.Height); R := Rect(0,0,Image2.Width, Image2.Height); PNG.Canvas.CopyRect(R,Image2.Picture.Icon.Canvas, R); PNG. SavetoFile('TuxTest.png'); PNG.Free;end;                         And when do you sleep? All day on the forum and coding .... Winni Thanks Winni... I see you in every post too I love comp. programming and like to help others schoolmates with some ideas for projects. (I'm not expert in Lazarus) Love this forum, I was about to stop using Lazarus, I was gonna use CodeTyphon instead but its forum is dead xD I will try your code soon. Best regards Winni ---------------------------------------------------------------------- SaraT · 2020-02-16 00:06 Winni... I got a error :/ Cannot assign a TIcon to a TIcon I haven't changed anything. What could be? Thanks again. ---------------------------------------------------------------------- winni · 2020-02-16 00:23 Hi! ????? * The error message is nonsense *  have tested the code - no problem. Does the debugger show  a linenumber where it crashed? Project --> Options --> Debugging -- > Display line number in run-time errors backtraces Enable this option if it is not done by default. The second trick is to insert bevor or after critical code a "showmessage" so that you can be shure that the app in this line is still alive. Mystery, mystery ..... Winni ---------------------------------------------------------------------- SaraT · 2020-02-16 00:31 Quote from: winni on February 16, 2020, 01:23:09 am Hi! ????? * The error message is nonsense *  have tested the code - no problem. Does the debugger show  a linenumber where it crashed? Project --> Options --> Debugging -- > Display line number in run-time errors backtraces Enable this option if it is not done by default. The second trick is to insert bevor or after critical code a "showmessage" so that you can be shure that the app in this line is still alive. Mystery, mystery ..... Winni Sorry Winni, now it works (I know what happened)... I created an empty project to tried it but the PNG has black background, thats all :/ Thanks Winni ---------------------------------------------------------------------- winni · 2020-02-16 00:57 Hi! Insert this lines at the beginning of the procedure: 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 Image2.Transparent := True;  If the icon in the image has a black background we have to look for another solution. The problem is that Microsoft forgot the transparency. All tricks to make an image transparent are only lousy hacks. I know there is a way to achieve this, but I forgot because I use now graphic libraries like BGRA where it is no problem. Winni ---------------------------------------------------------------------- SaraT · 2020-02-16 01:07 Still png in black :/ Can we save the PNG from a TPaintBox control? Not a TImage. If not we will have to try the hack with BGRA... I already have it installed. Thanks. ---------------------------------------------------------------------- winni · 2020-02-16 01:28 Hi! Got it again ! You have to define a not used color for transparency. By default this is fuchsia - because it's so ugly, that nobody uses it. The code is now: 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.Button3Click(Sender: TObject); begin Image2.Picture.Icon.TransparentColor:= clFuchsia; Imag e2.Picture.Icon.LoadFromFile('TuxMonTransparent.ico'); Image2.Picture. PNG.SaveToFile('TuxTest.png');end; Works with Linux without a probleml. Don't know about Windows. If not we will do it with BGRA. As proof: A beer drinking Tux with a  transparent hole! Winni ---------------------------------------------------------------------- SaraT · 2020-02-16 01:37 Quote from: winni on February 16, 2020, 02:28:27 amHi! Got it again ! You have to define a not used color for transparency. By default this is fuchsia - because it's so ugly, that nobody uses it. The code is now: 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.Button3Click(Sender: TObject); begin Image2.Picture.Icon.TransparentColor:= clFuchsia; Imag e2.Picture.Icon.LoadFromFile('TuxMonTransparent.ico'); Image2.Picture. PNG.SaveToFile('TuxTest.png');end; Works with Linux without a probleml. Don't know about Windows. If not we will do it with BGRA. As proof: A beer drinking Tux with a  transparent hole! Winni Many, many thanks Winni. Worked in Windows 10 with transparency  Many thanks for your time... I owe you a beer. See you in next post xD ---------------------------------------------------------------------- winni · 2020-02-16 02:28 Quote from: SaraT on February 16, 2020, 02:37:09 am I owe you a beer. I hope that it is not a Corona ........ https://en.wikipedia.org/wiki/Corona_(beer) Winni