Forum > LCL

Saving form contents as image partially

(1/2) > >>

Leledumbo:
I have an application with this layout:

--- Code: ---+--Form---+
|+-------+|
|| Image ||
|+-------+|
|+-------+|
|| Panel ||
|+-------+|
|+-------+|
||Button ||
|+-------+|
+---------+

--- End code ---
And I need to save as image the image and panel part. How can I do so?

So far, though haven't tried, my crazy idea is to copy Canvas.Pixels from top left of image to bottom right of panel. But I'm not sure.

LazaruX:
Do you mean making a kind of screenshot of Image and Panel together? If you mean this, you could just try to make a partial screenshot.

Zoran:
I found this on Wiki:

http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen

I haven't tried it though.

Zoran:
Now I tried and this saves the screenshot of the form:


--- Code: ---procedure TForm1.Button2Click(Sender: TObject);
var
  MyBitmap: TBitmap;
  MyDC: HDC;
begin
  MyDC := GetDC(Self.Handle);
  MyBitmap := TBitmap.Create;
  try
    MyBitmap.LoadFromDevice(MyDC);
    MyBitmap.SaveToFile('FormsAppearance.bmp');
  finally
    ReleaseDC(Self.Handle, MyDC);
    FreeAndNil(MyBitmap);
  end;
end;

--- End code ---

Leledumbo:

--- Quote ---you could just try to make a partial screenshot
--- End quote ---
That's another idea, too. The problem is, what do I have to set to limit the region of the TBitmap (my knowledge about this class isn't too deep)? Plus, is there any easy way to get the top left of the image and bottom right of the panel? The screenshot will take a whole screen, so I can't use relative position to the form.

--- Quote ---I found this on Wiki
--- End quote ---
Yes, I've seen that page. Combined with what BPsoftware suggests, I can make it right.

Navigation

[0] Message Index

[#] Next page

Go to full version