1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++Builderでフォームの内容を画像として保存する

Posted at

フォームを用意する。

ファイル->新規作成->マルチデバイスアプリケーション
でプロジェクトを作成したら、適当な名前をつけて保存。
例:
プロジェクト名::TestScreen
フォーム名::main.cpp

出力用フォームを用意する。

ファイル->新規作成->マルチデバイスフォーム
で出力フォームを作成。
フォーム名::screen.cpp

キャプチャ.PNG

出力フォームにTPanelと出力内容を配置。

出力フォームにTPanelを配置して、その中に出力内容を入れる。
(TPanelじゃなくてもTControlを基底クラスにしているものなら出来ると思う。)
例:
TPanel::Name:Panel1
TLabel::Name:Label1
::Text:Test

2.PNG

メインフォームにボタンを設置

メインフォームにボタンを設置し、下記のようなスクリプトを記述

main.h
// --省略
// 出力フォームをinclude
# include "screen.h"
// --省略
main.cpp
// --省略
// ボタンスクリプト
void __fastcall TForm1::Button1Click(TObject *Sender) {
	// 出力フォームのインスタンス
	TForm2* print_form = new TForm2(this);
	// TBitmapのインスタンス
	Fmx::Graphics::TBitmap * bitmap;
	// MakeScreenMethodでビットマップを生成
	bitmap = print_form->Panel1->MakeScreenshot();
	// test.pngという名前で出力
	bitmap->SaveToFile(L"test.png");
	// 後処理
	delete bitmap;
	delete print_form;
}
// --省略

test.png

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?