Recent

Author Topic: Create and export a SVG file (TBGRASVG) from a TChart canvas?  (Read 330 times)

bhreis88

  • New Member
  • *
  • Posts: 20
Hi there,

I've been trying to export a TChart canvas to a SVG file with TBGRASVG from BGRABitmapPack without much success. The attached example produces a blank svg file and that is as far as I reached.

What am I missing there?

For the record, I do know about TADrawerSVG and it works for me. I just want to learn how to implement with TBGRASVG also.

Thanks!

P.S. If you do not wish to download the project, this is the key method in my implementation:
Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.  bmp: TBGRABitmap;
  4.  svg: TBGRASVG;
  5. begin
  6.  bmp:= TBGRABitmap.Create;
  7.  try
  8.   svg:= TBGRASVG.Create(Chart1.Width,Chart1.Height,cuPixel);
  9.   try
  10.    if (Chart1.Width > 0) and (Chart1.Height > 0)
  11.    then
  12.      begin
  13.        bmp.SetSize(Chart1.Width,Chart1.Height);
  14.        bmp.GetImageFromCanvas(Chart1.Canvas,0,0);
  15.        svg.Draw(bmp.Canvas2D,0,0,cuPixel);
  16.        svg.SaveToFile('test.svg');
  17.      end;
  18.   finally
  19.    svg.Free;
  20.   end;
  21.  finally
  22.   bmp.Free;
  23.  end;
  24. end;

bhreis88

  • New Member
  • *
  • Posts: 20
Re: Create and export a SVG file (TBGRASVG) from a TChart canvas?
« Reply #1 on: July 02, 2019, 01:24:43 pm »
I forgot to mention my specs:
FPC 3.0.4 + Lazarus 2.0.2 32bit + BGRABitmapPack 9.9.4 + TAChartBgra 1.0 on Windows 10 Home 1803

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: Create and export a SVG file (TBGRASVG) from a TChart canvas?
« Reply #2 on: July 02, 2019, 02:19:03 pm »
Hi

The GetImageFromCanvas retrieves the pixel content, not the vectorial shapes. So you won't get any SVG like that.

Also, the Draw function the SVG is to render the SVG on a surface, not to add an image.

Basically, what you would need to do is to create a drawer, a bit like TADrawerSVG, that would create the vectorial object in the SVG.

To add objects in an SVG, you can do it via its Content property and Append... functions, though this is still a bit experimental.

Regards
Conscience is the debugger of the mind

bhreis88

  • New Member
  • *
  • Posts: 20
Re: Create and export a SVG file (TBGRASVG) from a TChart canvas?
« Reply #3 on: July 02, 2019, 03:34:57 pm »
Hi, circular,

thanks for clarifying a lot. I thought something like this was already possible given that the TAChartBgra gui connector is available, so I kept looking for any possible ways of achieving it. I see how far I am from it now...

I will try playing with the Content property then and let you know how it goes.

BTW, thanks for developing this amazing package and congrats on the latest release!

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: Create and export a SVG file (TBGRASVG) from a TChart canvas?
« Reply #4 on: July 02, 2019, 10:23:22 pm »
I will try playing with the Content property then and let you know how it goes.
Cool. I am curious about that. I haven't investigated much in this direction however I am sure there's room for improvement.

Quote
BTW, thanks for developing this amazing package and congrats on the latest release!
Thanks.  :)

Hopefully I can finally also release a version of LazPaint.  :)
Conscience is the debugger of the mind