I use this code to save a screenshot of a Form to a bitmap file:
var
Bmp : Graphics.TBitmap;
begin
Bmp := GetFormImage;
try
Bmp.SaveToFile( _DestFilePath );
finally
Bmp.Free;
end;
end;
However, it doesn't seem to work well when a TRichEdit
control is placed on the Form. Instead of a TRichEdit control and all its content, a white rectangle is saved into the final image.
How can I get a complete screenshot of a Form that contains a non-blank TRichEdit
control?
I use Delphi 2009.
If GetFormImage()
fails, you should try to BitBlt()
the Form's contents yourself, eg:
var bm := TBitmap.Create(ClientWidth, ClientHeight);
try
BitBlt(bm.Canvas.Handle, 0, 0, ClientWidth, ClientHeight, Self.Canvas.Handle, 0, 0, SRCCOPY);
// use bm as needed...
finally
bm.Free;
end;
This successfully copies a Form with a TRichEdit
for me.