Setting the size of a TChart when saved/copied to clipboard
Posted: 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.
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;