Page 1 of 1

Problem with TeeCreateBitmap function

Posted: Thu Oct 23, 2008 4:02 pm
by 10550553
I use TeeChart Pro v8.04 with Delphi2006.

I want to create a bitmap of my chart to insert it in a report (who is producted by my software).

So I use the TeeCreateBitmap function to create a Bitmap. And this Bitmap is draw on a canvas for printing.
But On the paper, the legend, the title Axis and the title Chart (all fonts) are very small .

Code: Select all

MyBitmap :TBitmap;
Chart1 :TChart;
Canvas : TCanvas;
...

MyBitmap := chart1.TeeCreateBitmap(clWhite,FRect,pf8bit);
Canvas.draw(myRect.Left,myRect.Top,MyBitmap);
I found a solution : saving chart to a bitmap file and loading this file to draw in a printer canvas.

Code: Select all

MyBitmap :TBitmap;
Chart1 :TChart;
...

Chart1.SaveToBitmapFile('C:\temp\mychart.bmp');
MyBitmap := chart1.TeeCreateBitmap(clWhite,FRect,pf8bit);
MyBitmap.loadfromfile('C:\temp\mychart.bmp');
Canvas.draw(myRect.Left,myRect.Top,MyBitmap);
Is there a better way to solve my problem and avoid saving to a file ?

Posted: Mon Oct 27, 2008 12:29 pm
by narcis
Hi DelD,

We can think of two ways to achieve what you request:

1. You could use StretchDraw technique as shown here.
2. If you are interested in using a bitmap you can do somethink like the code snippet below which prints all texts correctly.

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
var
tmpBmp : tbitmap;
customRect : TRect;
begin

 With CustomRect do
  begin
    Left := 0;
    Top := 0;
    Right :=  Chart1.Width;
    Bottom :=  Chart1.Height;
  end;

 tmpBmp := Tbitmap.Create;
  try

    tmpBmp.PixelFormat := pf8bit;
    tmpBmp.Width := (CustomRect.Right - CustomRect.Left);
    tmpBmp.Height := (CustomRect.Bottom - CustomRect.Top);

    tmpBmp.Canvas.Brush.Color := clYellow;
    tmpBmp.Canvas.Brush.Style := bsSolid;
    tmpBmp.Canvas.CopyRect(Rect(0,0,Chart1.Width,Chart1.Height),
           Chart1.Canvas.ReferenceCanvas,CustomRect);

    tmpBmp.Canvas.TextOut(10,10,'hello world');

    Printer.BeginDoc;
    Printer.Canvas.StretchDraw(Rect(1,1,Printer.PageWidth - 1,
    Printer.PageHeight - 1),tmpBmp);
    Printer.EndDoc;
  finally
    tmpBmp.Free;
  end;

end;