* * *

Author Topic: SOLVED: How to use SVG images  (Read 379 times)

fatmonk

  • Full Member
  • ***
  • Posts: 137
SOLVED: How to use SVG images
« on: May 17, 2017, 06:32:16 pm »
Reading around it seems that BGRABitmap now supports SVG... but I can't find any info on how to use SVG images and exactly what is supported.

I have a couple of SVG icons I want to display and scale along with a UI.

Can anyone point me in the right direction?

Thanks,

FM
« Last Edit: May 19, 2017, 01:46:24 pm by fatmonk »

Handoko

  • Hero Member
  • *****
  • Posts: 991
  • My goal: build my own game engine using Lazarus
Re: How to use SVG images
« Reply #1 on: May 17, 2017, 06:39:52 pm »
I do not use BGRABitmap, but I think you may download and try the TEST SVG from this thread:

https://forum.lazarus.freepascal.org/index.php?topic=36692.0

fatmonk

  • Full Member
  • ***
  • Posts: 137
Re: How to use SVG images
« Reply #2 on: May 18, 2017, 04:47:57 pm »
I downloaded that (I'd read that thread but missed the attachment at the top!) and have had a play with the test project.

After a bit of playing around I've got a version of that test project (attached) that allows me to scale an SVG on the fly (kind of brute forcing it a bit, so there may be a slicker, more efficient way of doing it).

However, the test project only reads from a file. I'd like to include the SVG(s) with the executable. I'll play some more, but ideally I'd be able to include the XML of the SVG directly in my project and create the in-UI image from that - that would even allow me to manipulate things like the colours in the graphic on the fly...

-FM

fatmonk

  • Full Member
  • ***
  • Posts: 137
Re: How to use SVG images
« Reply #3 on: May 18, 2017, 05:06:47 pm »
OK, a bit more progress...

Using the StringToStream() function from this StackExchange answer I have managed to include the SVGs as string variables directly in the code.

New version attached.

I am, however, getting a load of messages from Heap Trace (heaptrc) when exiting this test project, so I am reluctant to add this code to my live project... What am I doing wrong to get these heap errors?

-FM

avra

  • Hero Member
  • *****
  • Posts: 917
    • Additional info
Re: How to use SVG images
« Reply #4 on: May 18, 2017, 06:26:04 pm »
ct2laz - Easily convert components and projects between Lazarus and CodeTyphon

fatmonk

  • Full Member
  • ***
  • Posts: 137
Re: How to use SVG images
« Reply #5 on: May 18, 2017, 06:38:59 pm »
I should have pointed out that I want this to be cross platform!

I think embedding the SVG XML as a text string is the way I'm going to achieve this as it allows me to manipulate the image colours etc as well.

-FM

fatmonk

  • Full Member
  • ***
  • Posts: 137
Re: How to use SVG images
« Reply #6 on: May 19, 2017, 01:46:06 pm »
Here's a much simpler example.

- It uses an embedded SVG string as the scalable graphic to everything is self contained.
- It uses BGRABitmap and BGRASVG only.
- It doesn't appear to suffer from any memory leaks (feel free to test and let me know if it does as this is an area I want to learn more about).
- It should be cross platform as it does not rely on any windows specific resource embedding.

To test, simply run and try rescaling the form and the SVG scales smoothly...

-FM

(Demo Built and tested with BGRABitmap 9.5)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus