Question :convert tpanel.canvas to bitmap when panel out of form bounds? lazarus / 39-Graphics ---------------------------------------------------------------------- Josh · 2017-11-20 19:55 Hope someone can help here. 5+ years ago I was playing around with panel canvas, ie copying a panel canvas as a bitmap; that could then be used in another document format. As many image permutations and resolutions were being done, I thought I had created the panel way off the forms boundary ( out of users view). Unfortunately I cannot find the code I used back then, but my memory tells me that I just copied the tpanel canvas to a bitmap; when I try this the area of the panel that is off the visible screen is blank. If I move the panel into the visible area, then the visible part becomes part of the tbitmap. Has something changed, or is there another way to grab the contents of a tpanel that is outside the screen bounds? Code: [Select]var bmp:tbitmap; begin   bmp:=tbitmap.Create;   bmp.Width:=panel1.Width;   bmp.Height:=panel1.Height;   panel1.Left:=-panel1.Width+trackbar1.Position;   bmp.Canvas.CopyRect(rect(0,0,panel1.Width,panel1.Height),panel1.Canv as,rect(0,0,panel1.Width,panel1.Height));   image1.Picture.Bitmap:=bmp; // temp dump bmp to timage.   bmp.Free; end; Trackbar used to bring panel in/out of focus of screen, image1 is a timage that I drop the copied bmp onto to see what is happening. ---------------------------------------------------------------------- wp · 2017-11-20 21:36 This function 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 function CreatePanelImage(APanel: TPanel): TBitmap;begin  Result := TBitmap.Create;  try    Result.SetSize(APanel.ClientWidth, APanel.ClientHeight);    Result.Canvas.Brush.Color := clWhite;    Result.Canvas.FillRect(0, 0, Result.Width, Result.Height);    APanel.PaintTo(Result.Canvas, 0, 0);  except    Result.Free;    raise;  end;end; seems to work even for an off-screen panel (at least on Windows - did not test anything else). See attached demo ---------------------------------------------------------------------- Josh · 2017-11-20 23:45 Hi WP, Thanks for your suggestion. I have created a little test app using the function, but it still shows an issue, if the panel has an image on it, this is not copied to the tbitmap. It copies the 2 controls I have placed on the form, but not the image. ---------------------------------------------------------------------- Josh · 2017-11-20 23:47 Pic, after transfer ---------------------------------------------------------------------- Josh · 2017-11-21 01:07 Hi I created a procedure that does similar, Not sure how cross-platform it is though. Code: [Select]procedure GetControlAsBitmap(AControl :TWinControl;ABitmap:TBitmap); var   DC: HDC; begin   // quick check to make sure control and bitmap are assigned.   if not Assigned(ABitmap) then Exit;   if not Assigned(AControl) then Exit;   DC :=GetWindowDC(AControl.Handle);   ABitmap.Width  :=AControl.Width;   ABitmap.Height :=AControl.Height;   BitBlt(ABitmap.canvas.Handle,0,0,ABitmap.Width,ABitmap.Height,dc,0,0 ,SrcCopy);   ReleaseDC(AControl.Handle, DC); end; ---------------------------------------------------------------------- wp · 2017-11-21 09:37 Quote from: josh on November 21, 2017, 12:45:48 amHi WP, Thanks for your suggestion. I have created a little test app using the function, but it still shows an issue, if the panel has an image on it, this is not copied to the tbitmap. It copies the 2 controls I have placed on the form, but not the image. It does if the panel's ParentColor is off.