Recent

Author Topic: Ignoring viewBox TBGRASVG  (Read 330 times)

AsleyCruz

  • Full Member
  • ***
  • Posts: 108
    • Graphic and web designer
Ignoring viewBox TBGRASVG
« on: October 14, 2024, 03:10:14 pm »
Hi coders, I would like to fit/stretch the SVG content to the component,
ignoring the viewBox of the SVG to crop any transparent pixel.

How can I do this?
Please, check out the attached image and the code.

Thanks a lot.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. Var
  3.  bmp: TBGRABitmap;
  4.  svg: TBGRASVG;
  5. begin
  6.  bmp:= TBGRABitmap.Create;
  7.  svg:= TBGRASVG.Create('icon.svg');
  8.  try
  9.   try
  10.     bmp.SetSize(Round(Image1.Width),Round(Image1.Height));
  11.     bmp.Fill(clRed);
  12.     svg.StretchDraw(bmp.Canvas2D,0,0,Image1.Width,Image1.Height);
  13.     Image1.Picture.Bitmap.Assign(bmp);
  14.   finally
  15.     svg.Free;
  16.   end;
  17.  finally
  18.   bmp.Free;
  19.  end;
  20. end;
« Last Edit: October 14, 2024, 03:12:07 pm by AsleyCruz »
Graphic & web designer

circular

  • Hero Member
  • *****
  • Posts: 4378
    • Personal webpage
Re: Ignoring viewBox TBGRASVG
« Reply #1 on: October 22, 2024, 08:30:31 am »
Hi Ashley,

I understand you would like to remove in this case the top and bottom empty space, filled in red in the screenshot.

There isn't a function yet to do that. For this, one need a function to compute the actual bounds of an SVG object. It can be tricky in some cases, for example with texts and line joins.

In the meantime, if that's for an application UI, I would recommend to edit the SVG files to change its bounds. You can do that with LazPaint or with Inkscape.

Regards
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018