home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Print as Bitmap example }
- { Copyright (c) 1995-1997 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit UPriBit;
-
- interface
-
- { This example prints a TeeChart component using a temporary
- TBitmap image object.
-
- This can be used with printers not fully supporting the
- Windows metafile format (or printers with buggy printer drivers).
-
- The advantadge of using this code is to specify custom
- pixel dimensions both for the Bitmap/Metafile and the printer
- paper coordinates.
-
- By default, TeeChart prints and scales in a very dependant way
- on screen coordinates. This is designed to obtain a "wysiwyg"
- Chart on paper, but in some circunstances you might want to
- avoid this automatic scaling and specify your own coordinates.
-
- Bitmaps are much slower to print than metafiles and consume more
- memory. This can make to fail on some printers.
- Also, bitmap output has poor resolution compared to metafiles,
- but it can be a solution when the printer drivers have
- bugs supporting the Windows metafile format.
-
- }
- uses
- Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- TeEngine, Series, TeePolar, ExtCtrls, TeeProcs, Chart, StdCtrls, Buttons;
-
- type
- TFormPrintBitmap = class(TForm)
- Chart1: TChart;
- Series1: TBarSeries;
- BitBtn2: TBitBtn;
- Button1: TButton;
- procedure FormCreate(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- implementation
-
- uses Printers;
-
- {$R *.DFM}
-
- procedure TFormPrintBitmap.FormCreate(Sender: TObject);
- begin
- Series1.FillSampleValues(20); { <-- sample values }
- end;
-
- { Example: Create a bitmap image and send it to the printer.
- Here the bitmap is created from a metafile, but
- it can also be created directly from a Chart:
-
- Bitmap:=TBitmap.Create;
- try
- Bitmap.Width:=Chart1.Width;
- Bitmap.Height:=Chart1.Height;
- Chart1.Draw(Bitmap.Canvas,Rect(0,0,Bitmap.Width,Bitmap.Height));
- Printer.Canvas.StretchDraw(Rect(500,500,2000,2000), Bitmap);
- finally
- Bitmap.Free;
- end;
- }
-
- procedure TFormPrintBitmap.BitBtn2Click(Sender: TObject);
- var Meta:TMetafile;
- Bitmap:TBitmap;
- begin
- Meta:=Chart1.TeeCreateMetafile(True,Rect(0,0,800,800));
- try
- Printer.BeginDoc;
- try
- Bitmap:=TBitmap.Create;
- try
- Bitmap.Width:=1500;
- Bitmap.Height:=1500;
- Bitmap.Canvas.Draw(0,0,Meta);
- Printer.Canvas.StretchDraw(Rect(500,500,2000,2000), Bitmap);
- finally
- Bitmap.Free;
- end;
- finally
- Printer.EndDoc;
- end;
- finally
- Meta.Free;
- end;
- end;
-
- procedure TFormPrintBitmap.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-