0
1

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 XE4 > FastReport VCL 5 > PDF Export > TEdit付きのChart1をFastReportへ送る (クリップボード経由) > 解像度は72dpi

Last updated at Posted at 2018-12-06
動作環境
C++ Builder XE4
TeeChart Lite v2013.08.130414 32bit VCL
FastReport VCL 5 (XE4標準ではなく、別途インストール)

前置き

関連

参考

  • クリップボードからFastReportのPicture1への読込みについて

両方の情報を合わせて実装しました。
情報感謝です (I appreciate your information)。

実装

  • Panel1上にChart1とEdit1を配置
  • Panel1の配置が分かるように色づけした (緑色)
Unit1.h
//---------------------------------------------------------------------------

# ifndef Unit1H
# define Unit1H
//---------------------------------------------------------------------------
# include <System.Classes.hpp>
# include <Vcl.Controls.hpp>
# include <Vcl.StdCtrls.hpp>
# include <Vcl.Forms.hpp>
# include <Vcl.ExtCtrls.hpp>
# include <VCLTee.Chart.hpp>
# include <VCLTee.TeEngine.hpp>
# include <VCLTee.TeeProcs.hpp>
# include "frxClass.hpp"
# include "frxExportPDF.hpp"
# include <VCLTee.Series.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TButton *Button1;
	TPanel *Panel1;
	TChart *Chart1;
	TEdit *Edit1;
	TFastLineSeries *Series1;
	TfrxReport *frxReport1;
	TfrxPDFExport *frxPDFExport1;
	void __fastcall Button1Click(TObject *Sender);
	void __fastcall FormShow(TObject *Sender);
	void __fastcall frxReport1BeforePrint(TfrxReportComponent *Sender);

private:	// ユーザー宣言
	void __fastcall copyToClipboard(TPanel *panelPtr);
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
# endif
Unit1.cpp
//---------------------------------------------------------------------------

# include <vcl.h>
# pragma hdrstop

# include <ClipBrd.hpp>
# include <DateUtils.hpp>
# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma link "frxClass"
# pragma link "frxExportPDF"
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	// PDFエクスポート
	frxPDFExport1->FileName = L"test.pdf";
	frxPDFExport1->ShowDialog = true;
	frxPDFExport1->Quality = 100;
	frxReport1->PrepareReport(/* clearLastReport= */true);
	frxReport1->Export(frxPDFExport1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
	// ダミーデータでグラフ生成
	Chart1->Series[0]->XValues->DateTime = true;
	Chart1->BottomAxis->DateTimeFormat = L"nn:ss";

	TDateTime dt;

	dt = Now();

	double yval;
	for (int idx=0; idx < 10; idx++) {
		yval = (1+ idx) % 2;
		Series1->AddXY(dt, yval, "", clRed);
		dt = IncSecond(dt, 1);
	}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::copyToClipboard(TPanel *panelPtr)
{
	if (panelPtr == NULL) {
		return; // error
	}

	TBitmap *lBmp = new TBitmap();
	try {
		lBmp->SetSize(panelPtr->ClientWidth, panelPtr->ClientHeight);
		HDC dc = GetDC(panelPtr->Handle);
		BitBlt(lBmp->Canvas->Handle, 0, 0, panelPtr->ClientWidth, panelPtr->ClientHeight, dc, 0, 0, SRCCOPY);
		Clipboard()->Assign(lBmp);
	} catch (...) {
	}
	delete lBmp;
}

void __fastcall TForm1::frxReport1BeforePrint(TfrxReportComponent *Sender)
{
	if (Sender->Name == L"Picture1") {
		// Note:
		//   Edit1とChart1をChart1->TeeCreateMetafile()でFastReportへ送ることができない
		//   そのため、Bitmapにしてクリップボード経由で送る
		//

		// 1. クリップボードへTEdit付きのChart1をコピー
		copyToClipboard(Panel1);

		// 2. クリップボードからPicture1へコピー
		TClipboard *pCB = Clipboard();
		TfrxPictureView *picptr = (TfrxPictureView *)Sender;

		picptr->Picture->LoadFromClipboardFormat(CF_BITMAP, pCB->GetAsHandle(CF_BITMAP), 0);
	}
}
//---------------------------------------------------------------------------

フォームデザイン

2018-12-06_17h27_11.png

実行例

  1. Button1を押下
  2. PDFへのエクスポートダイアログで[OK]を押す
  3. 保存先フォルダを選択する

ソフトの画面
2018-12-06_17h35_04.png

PDFへのエクスポートダイアログ
2018-12-06_17h38_46.png

生成されたpdfファイル
(PDF-XChange Viewerで開いた状況)

2018-12-06_17h35_23.png

Edit1もきちんとFastReportへ送ることができている。

画像がつぶれる場合

上記を使って画像がつぶれる場合、Button1Click()にて下記を追加する。

frxPDFExport1->PrintOptimized = true;  // これがないと貼り付けた画像がつぶれた状態になる

つぶれる度合いがある程度緩和されるが、まだ汚い場合がある。

解像度は72dpi

クリップボード経由(Bitmap)の場合72dpiになってしまうようだ。

解像度を変更したJpegをクリップボードから貼り付けるには?
https://www.papy.in/bbs/delphi/200704/07040059.html

// SaveToClipboardFormatではBitmap形式になり解像度が72dpiに戻る

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?