Setting the size of a TChart when saved/copied to clipboard

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
hvpd
Newbie
Newbie
Posts: 1
Joined: Mon Feb 18, 2008 12:00 am

Setting the size of a TChart when saved/copied to clipboard

Post by hvpd » Thu Jan 21, 2016 11:47 am

We have a number of charts in our application which we allow the user to generate a report in Word from. We do this by calling CopyToClipboardBitmap on the TChart and then pasting it into the Word document at the appropriate location.

However, we're having issues that the resolution of the bitmaps are based on their currently rendered size on screen. So people on low resolution desktops, or who happen to not be running the app maximized end up with quite low resolution images in the generated Word document.

We'd like to be able to set the resolution before doing the CopyToClipboardBitmap. Is there anyway to do this?

Note, we've tried using CopyToClipboardMetafile (with both true and false as the argument) and that seems to have similar issues in that the size of the image is based on the rendered size on screen. This results in the text for the axis, labels, etc. being overly large when made larger within the document. So we're back to wanting to be able to specify the render size that the CopyToClipboardBitmap / CopyToClipboardMetafile / SaveToBitmapFile / SaveToMetafile / SaveToMetafileEnh is based upon.

Code: Select all

procedure copyToClipboard(const aChart: TChart);
var
	guid: TGUID;
    str: String;
begin
	SysUtils.CreateGUID(guid);
	str := StringUtils.ToStr(guid);

	aChart.CopyToClipboardBitmap();
    aChart.SaveToBitmapFile('C:\temp\' + str + '.bmp'); // DEBUG
//	aChart.CopyToClipboardMetafile(false);
    aChart.SaveToMetafile('C:\temp\' + str + '.wmf'); // DEBUG
//	aChart.CopyToClipboardMetafile(true);
    aChart.SaveToMetafileEnh('C:\temp\' + str + '.emf'); // DEBUG
end;

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Setting the size of a TChart when saved/copied to clipboard

Post by Yeray » Thu Jan 21, 2016 2:50 pm

Hello,

You can set a TRect as parameter for the CopyToClipboardBitmap method. Ie:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var tmpRect: TRect;
    tmpWidth, tmpHeight: Integer;
begin
  tmpRect:=Chart1.GetRectangle;
  tmpWidth:=tmpRect.Right-tmpRect.Left;
  tmpHeight:=tmpRect.Bottom-tmpRect.Top;
  tmpRect.Right:=tmpRect.Right+tmpWidth;
  tmpRect.Bottom:=tmpRect.Bottom+tmpHeight;
  Chart1.CopyToClipboardBitmap(tmpRect);
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply