[SOLVED] Copying canvas rect lazarus / 39-Graphics ---------------------------------------------------------------------- stormfinger · 2020-04-12 17:42 hi in the folowing code i try to copy certain Rectangle from png.. this code results in bad unrecognized picture format ..but it runs without error. if i skip png2  and use png to assign to pict2 it works ok ...rectangle values have been also changed to 100 100 200 200 ..stil unrecognizable format.  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  var png, png2  : TPortableNetworkGraphic;   myPict2: TPicture;    sourceR: TRect; begin    sourceR := TRect.Create(0, 0, 700, 700);;    myPict2 := TPicture.create();  png := TPortableNetworkGraphic.Create();  png2 := TPortableNetworkGraphic.Create();   ScreenDC := GetDC(0);  png.LoadFromDevice(ScreenDC);   png2.Canvas.CopyRect(sourceR,png.Canvas,sourceR);    myPict2.PNG.Assign(png2);  myPict2.PNG.SaveToFile('test.png');end;  thank you for your time ---------------------------------------------------------------------- eljo · 2020-04-12 18:06 you are not initializing png2 properly. It has no bit depth, canvas size, or any other image property set and you assume that the size of the image in both pngs is identical you might need to differentiate sourceR and DestR in the final solution. ---------------------------------------------------------------------- stormfinger · 2020-04-29 11:22 thank you for your hint ..i added Canvas.Create and set its size now its working ---------------------------------------------------------------------- eljo · 2020-04-29 18:24 Quote from: stormfinger on April 29, 2020, 01:22:25 pmthank you for your hint ..i added Canvas.Create and set its size now its working remove canvas.create. Its only used when the canvas object is created and that is called automatically from the TPortableNetworkGraphic.Create(); line of code. You just created a memory leak (best case).