PNG Export

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
to2
Newbie
Newbie
Posts: 39
Joined: Thu Jan 19, 2006 12:00 am

PNG Export

Post by to2 » Thu Apr 06, 2006 3:31 pm

The PNG export of a chart to clipboard or file is quite easy. But is it possible to write some more information to the canvas before exporting it?

Example.

I have a FastLine series with cursor. I'd like to export the chart and the numeric information for cursor x and y position. To prepare this for Bitmap export I do

Code: Select all

Chart1->CopyToClipboardBitmap();
Graphics::TBitmap* BMP = new Graphics::TBitmap;
BMP->Assign(Clipboard());
Now I access the BMP->Canvas, enlarge it, write some text under the chart etc.

Can I do something similar with TPNGExportFormat without drawing all to the visible chart? Can I assign a BMP to a TPNGExportFormat? There is a Bitmap() function for TPNGExportFormat with explanation
Sets or returns the bitmap used by the PNGExport
How can I set the bitmap used by the PNGExport? Bitmap() doesn't accept a parameter.
Best Regards

Thomas

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Apr 11, 2006 2:27 pm

Hi,

it cannot be assigned directly, TPNGExportFormat requires a Panel to be able to export it. One way I can think of is to assign the temporary bmp to a TDraw3D panel using the backImage and then assign it as Panel for the TPNGExportFormat.

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
var tmpBmp: TBitmap;
    CustomRect : TRect;
    tmpPanel :TDraw3D;
begin
  { setup custom chart rect }
  With CustomRect do
  begin
    Left := 0;
    Top := 0;
    Right := Left + 200;
    Bottom := Top + 200;
  end;
  { temporary bitmap }
  tmpBmp := TBitmap.Create;
  try
    tmpBmp.Width := (CustomRect.Right - CustomRect.Left);
    tmpBmp.Height := (CustomRect.Bottom - CustomRect.Top);
    tmpBmp.Canvas.CopyRect(Rect(0,0,tmpBmp.Width,tmpBmp.Height),
                          Chart1.Canvas.ReferenceCanvas,CustomRect);
    { now tmpBmp stores part of chart,
      you can save it to file, stream, clipboard, ... }
   With TPNGExportFormat.Create do
    try
      tmpPanel := TDraw3D.Create(self);
      tmpPanel.BackImage.Assign(tmpBmp);
      Panel :=tmpPanel;
      PixelFormat := pf24Bit;
      SaveToFile('d:\temp\test.png');
    finally
      Free;
    end;
  finally
    tmpBmp.Free;
  end;
end;

Post Reply