Firemonkeyでフォームの画像イメージを取得してビットマップに保存したいのですが,全くわかりません。何か方法がありますでしょうか。
FiremonkeyのコンポーネントにはMakeScreenshotメソッドがありますが、フォームには無いので
VCLでスクリーンショットを撮って
ストリームに保存して、Firemonkeyに渡す作業が必要みたいです。
(参考:http://stackoverflow.com/questions/10303256/how-to-take-a-screenshot-with-firemonkey-multi-platforms)
Windowsで成功したコードも書いておきます。
implementation
uses
Winapi.Windows, Vcl.Graphics, FMX.Platform.Win;
procedure TForm1.GetFormShot(var dest: FMX.Types.TBitmap);
var
cVCL : Vcl.Graphics.TCanvas;
bmpVCL: Vcl.Graphics.TBitmap;
msBmp : TMemoryStream;
begin
bmpVCL := Vcl.Graphics.TBitmap.Create;
cVCL := Vcl.Graphics.TCanvas.Create;
cVCL.Handle := GetWindowDC(FMX.Platform.Win.FmxHandleToHWND(Form1.Handle));
try
bmpVCL.Width := 640;
bmpVCL.Height := 473;
bmpVCL.Canvas.CopyRect(Rect(0, 0, 640, 473),
cVCL,
Rect(8, 30, 648, 503)
);
finally
ReleaseDC(0, cVCL.Handle);
cVCL.Free;
end;
msBmp := TMemoryStream.Create;
try
bmpVCL.SaveToStream(msBmp);
msBmp.Position := 0;
dest.LoadFromStream(msBmp);
finally
msBmp.Free;
end;
end;
うまくいきました!
VCLとFMXを混在させるんですね。
反則技に近いテクニックのように思いますが,役に立ちそうです。
ツイート | ![]() |