Draw hidden component to TBitmap lazarus / 39-Graphics ---------------------------------------------------------------------- GeorgeBakery · 2013-06-07 22:23 Hello everyone, is there a proper way to draw a hidden component canvas to a TBitmap? The thing is, I have a TPanel with a TLabel in it, the panel is hidden (visible:= false) and all I want to do is make a "screenshot" of this panel with that label. Long story short - I need to generate some sort of a "report" - TPanel will have fixed width and variable lenght (might be even longer than form) with labels and images in it and export this to a bitmap (and show on a small LCD). So far the best method I've tried is using PaintTo (TPanel.PaintTo), problem is, this only works if the panel is visible, and on Windows and Linux (GTK2) only. Same code on OSX will generate only black image. Thanks for helping me. ---------------------------------------------------------------------- BenJones · 2013-06-08 07:44 Been racking my head over this for the last hour I duno if this is what you want but I have managed to save contents of a panel when not visable. ok the trick I found is not to make the panel visable false, but just move it down the bottom of the form so it's not seen. Just resize your form so it not showing. here the code I used to save. Hope it may help. Code: [Select]var   bmp: tbitmap; begin   bmp := tbitmap.Create;   bmp.Width := panel1.Width;   bmp.Height := panel1.Height;   panel1.PaintTo(bmp.canvas.handle, 0, 0);   bmp.Canvas.Draw(0, 0, bmp);   bmp.SaveToFile('c:\out\shot.bmp'); ---------------------------------------------------------------------- exdatis · 2013-06-08 07:51 Thanks for the useful example! Regards ---------------------------------------------------------------------- GeorgeBakery · 2013-06-08 11:47 Quote from: BenJones on June 08, 2013, 09:44:04 amBeen racking my head over this for the last hour I duno if this is what you want but I have managed to save contents of a panel when not visable. ok the trick I found is not to make the panel visable false, but just move it down the bottom of the form so it's not seen. Just resize your form so it not showing. here the code I used to save. Hope it may help. Yes, this trick works perfectly on Windows, but not in GTK (Debian)  . Result: http://bake.sk/something/laz/cantest_bad.png If panel is visible and on form then it's ok: http://bake.sk/something/laz/cantest_good.png ---------------------------------------------------------------------- exdatis · 2013-06-08 11:50 Interesting, thanks for the information. Regards ---------------------------------------------------------------------- exdatis · 2013-06-08 11:52 Are you tried any kind of refreshment? ---------------------------------------------------------------------- Jurassic Pork · 2013-06-08 12:25 hello, you can try this code : Code: [Select]var bmp: tbitmap;     srect : Trect; begin  bmp := tbitmap.Create;  bmp.Width := panel1.Width;  bmp.Height := panel1.Height;  srect := Panel1.ClientRect;  Panel1.Visible := true;  Panel1.Refresh;  bmp.Canvas.CopyRect(srect,Panel1.Canvas,srect);  Panel1.Visible := false;  bmp.SaveToFile('/home/user/shot.bmp'); end;        work for me on Ubuntu 12.04    64 bits. The panel1 is not visible at design . Become visible only during the copy. Not very good because sometime during a short time we can see it. Friendly J.P ---------------------------------------------------------------------- exdatis · 2013-06-08 12:32 Thank you, Jurassic Pork, regards ---------------------------------------------------------------------- User137 · 2013-06-08 14:06 You need to call bmp.Free, sometime before the end of procedure. It is a serious programming error which could have different sorts of side- effects for the whole program.