home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / UPRIBIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.0 KB  |  108 lines

  1. {*********************************************}
  2. {  TeeChart Print as Bitmap example           }
  3. {  Copyright (c) 1995-1997 by David Berneda   }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit UPriBit;
  7.  
  8. interface
  9.  
  10. { This example prints a TeeChart component using a temporary
  11.   TBitmap image object.
  12.  
  13.   This can be used with printers not fully supporting the
  14.   Windows metafile format (or printers with buggy printer drivers).
  15.  
  16.   The advantadge of using this code is to specify custom
  17.   pixel dimensions both for the Bitmap/Metafile and the printer
  18.   paper coordinates.
  19.  
  20.   By default, TeeChart prints and scales in a very dependant way
  21.   on screen coordinates. This is designed to obtain a "wysiwyg"
  22.   Chart on paper, but in some circunstances you might want to
  23.   avoid this automatic scaling and specify your own coordinates.
  24.  
  25.   Bitmaps are much slower to print than metafiles and consume more
  26.   memory. This can make to fail on some printers.
  27.   Also, bitmap output has poor resolution compared to metafiles,
  28.   but it can be a solution when the printer drivers have
  29.   bugs supporting the Windows metafile format.
  30.  
  31. }
  32. uses
  33.   Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  34.   TeEngine, Series, TeePolar, ExtCtrls, TeeProcs, Chart, StdCtrls, Buttons;
  35.  
  36. type
  37.   TFormPrintBitmap = class(TForm)
  38.     Chart1: TChart;
  39.     Series1: TBarSeries;
  40.     BitBtn2: TBitBtn;
  41.     Button1: TButton;
  42.     procedure FormCreate(Sender: TObject);
  43.     procedure BitBtn2Click(Sender: TObject);
  44.     procedure Button1Click(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.   public
  48.     { Public declarations }
  49.   end;
  50.  
  51. implementation
  52.  
  53. uses Printers;
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TFormPrintBitmap.FormCreate(Sender: TObject);
  58. begin
  59.   Series1.FillSampleValues(20); { <-- sample values }
  60. end;
  61.  
  62. { Example: Create a bitmap image and send it to the printer.
  63.            Here the bitmap is created from a metafile, but
  64.            it can also be created directly from a Chart:
  65.  
  66.       Bitmap:=TBitmap.Create;
  67.       try
  68.         Bitmap.Width:=Chart1.Width;
  69.         Bitmap.Height:=Chart1.Height;
  70.         Chart1.Draw(Bitmap.Canvas,Rect(0,0,Bitmap.Width,Bitmap.Height));
  71.         Printer.Canvas.StretchDraw(Rect(500,500,2000,2000), Bitmap);
  72.       finally
  73.         Bitmap.Free;
  74.       end;
  75. }
  76.  
  77. procedure TFormPrintBitmap.BitBtn2Click(Sender: TObject);
  78. var Meta:TMetafile;
  79.     Bitmap:TBitmap;
  80. begin
  81.   Meta:=Chart1.TeeCreateMetafile(True,Rect(0,0,800,800));
  82.   try
  83.     Printer.BeginDoc;
  84.     try
  85.       Bitmap:=TBitmap.Create;
  86.       try
  87.         Bitmap.Width:=1500;
  88.         Bitmap.Height:=1500;
  89.         Bitmap.Canvas.Draw(0,0,Meta);
  90.         Printer.Canvas.StretchDraw(Rect(500,500,2000,2000), Bitmap);
  91.       finally
  92.         Bitmap.Free;
  93.       end;
  94.     finally
  95.       Printer.EndDoc;
  96.     end;
  97.   finally
  98.     Meta.Free;
  99.   end;
  100. end;
  101.  
  102. procedure TFormPrintBitmap.Button1Click(Sender: TObject);
  103. begin
  104.   Close;
  105. end;
  106.  
  107. end.
  108.