You've already forked lazarus-ccr
NiceChart: Implement save as bitmap.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8859 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -10,7 +10,7 @@ object Form1: TForm1
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
Position = poDesktopCenter
|
||||
LCLVersion = '2.3.0.0'
|
||||
LCLVersion = '3.99.0.0'
|
||||
object Label1: TLabel
|
||||
Left = 16
|
||||
Height = 15
|
||||
@@ -33,7 +33,7 @@ object Form1: TForm1
|
||||
Height = 25
|
||||
Top = 9
|
||||
Width = 105
|
||||
Caption = 'Save to WMF'
|
||||
Caption = 'Save to BMP'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 1
|
||||
end
|
||||
|
@@ -83,6 +83,7 @@ begin
|
||||
TickLength := 6;
|
||||
AxisYScale := 1000;
|
||||
OnMouseMove := ChartMouseMove;
|
||||
AdjustSize;
|
||||
end;
|
||||
Chart.BeginUpdate;
|
||||
Series := Chart.AddSeries(skBar);
|
||||
@@ -191,20 +192,33 @@ begin
|
||||
end;
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
{$IFNDEF FPC}
|
||||
var
|
||||
fn: String;
|
||||
{$IFDEF FPC}
|
||||
bmp: TBitmap;
|
||||
{$ELSE}
|
||||
m: TMetafile;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF FPC}
|
||||
ShowMessage('Function not implemented for Lazarus.');
|
||||
fn := 'test.bmp';
|
||||
bmp := Chart.CreateBitmap(Chart.ClientWidth, Chart.ClientHeight);
|
||||
try
|
||||
bmp.SaveToFile(fn);
|
||||
finally
|
||||
bmp.Free;
|
||||
end;
|
||||
{$ELSE}
|
||||
fn := 'test.emf';
|
||||
m := Chart.CreateMetafile;
|
||||
m.Enhanced := True;
|
||||
m.SaveToFile('test.emf');
|
||||
m.Free;
|
||||
ShowMessage('Saved to "test.wmf".');
|
||||
try
|
||||
m.Enhanced := True;
|
||||
m.SaveToFile(fn);
|
||||
finally
|
||||
m.Free;
|
||||
end;
|
||||
{$ENDIF}
|
||||
ShowMessage('Saved to "' + fn + '".');
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@@ -207,6 +207,8 @@ type
|
||||
function CreateMetafile: TMetafile;
|
||||
procedure CopyToClipboard;
|
||||
{$ENDIF}
|
||||
function CreateBitmap(AWidth, AHeight: Integer): TBitmap;
|
||||
procedure CopyToClipboardAsBitmap;
|
||||
published
|
||||
property AxisLineWidth: Integer read FAxisLineWidth write SetAxisLineWidth default 3;
|
||||
property ShowLegend: Boolean read FShowLegend write SetShowLegend default true;
|
||||
@@ -1640,6 +1642,38 @@ begin
|
||||
Changed;
|
||||
end;
|
||||
|
||||
function TNiceChart.CreateBitmap(AWidth, AHeight: Integer): TBitmap;
|
||||
var
|
||||
w, h: Integer;
|
||||
begin
|
||||
Calculate(AWidth, AHeight);
|
||||
if (RcLegend.Bottom > (AHeight - FOuterMargin))
|
||||
then h := RcLegend.Bottom + FOuterMargin
|
||||
else h := AHeight;
|
||||
if ((RcChart.Right - RcChart.Left) < (RcChart.Bottom - RcChart.Top))
|
||||
then w := AWidth + ((RcChart.Bottom - RcChart.Top) - (RCChart.Right - RcChart.Left))
|
||||
else w := AWidth;
|
||||
if (AWidth <> w) or (AHeight <> h)
|
||||
then Calculate(w, h);
|
||||
Result := TBitmap.Create;
|
||||
Result.Width := w;
|
||||
Result.Height := h;
|
||||
InternalPaint(Result.Canvas);
|
||||
Calculate(ClientWidth, ClientHeight);
|
||||
end;
|
||||
|
||||
procedure TNiceChart.CopyToClipboardAsBitmap;
|
||||
var
|
||||
bmp: TBitmap;
|
||||
begin
|
||||
bmp := CreateBitmap(ClientWidth, ClientHeight);
|
||||
try
|
||||
Clipboard.Assign(bmp);
|
||||
finally
|
||||
bmp.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$IFNDEF FPC}
|
||||
function TNiceChart.CreateMetafile: TMetafile;
|
||||
const
|
||||
|
Reference in New Issue
Block a user