cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to create dynamic SVG images as it can be done with Dynamic Bitmaps ?

PJEN
Senior

The SVGImage widget is a great tool but, as I understand it can only use SVG images from the SVGdatabase.
I may imagine to subclass the SVGImage class and handle directly run time created lists of VGObject as it is done with the SVGdatabase.
What is missing is to have the imageconverter tool code to run on the embedded platform. I mean the code that convert XML SVG text files to the VGShape , commands and points like those found in SVGDatabase.cpp.
Could this code part be disclosed or a new function  like 'dynamicSVGCreate( )' be added to the lib.
This function could return a VGObject being given a text string with the SVG content ?

Or do someone have an other solution to dynamically decode SVG XML text to bitmap ?

BR

Pierre

4 REPLIES 4
Osman SOYKURT
ST Employee

Hello @PJEN ,

This sounds interesting, but we would like to know why would you need to "handle directly run time created lists of VGObject"? Do you have a use-case scenario?

Osman SOYKURT
ST Software Developer | TouchGFX
PJEN
Senior

Hello Osman,

I'm currently working on a device that displays images from a file in relation to the GPS position of the device. This device is used on off road rallyes for example. The file format is like 'openrally' (see https://github.com/openrally/openrally) . Images may be PNG but also SVG.

My intent is not to support all the SVG features. For example the 'text' objects should be converted to 'paths' if needed.

Best regards

   Pierre

 

I would also be interested in this.

The idea is to make a composed Icon/button with 6-8 elements from SVGs.
Save the the biggest reusable bitmaps and cache them so that they can be used by 30+ instance of this custom widget/container. 
This widget would cause at most 10 dynamic bitmaps to be reused between different states of this widget.
By having it dynamically created, I could swap the colour pallet in the extra data and cache it.

What I can advise you is to make a copy of the 'SVGImage' class and add in this class a pointer to a 'VGObject' element. The idea is to copy the SVG image contained in SVGDatabase into the VGObject of this new class by dynamically allocating the memory for the VGObject and the list of associated VGShape (be careful with pointers in VGShape, such as 'points', 'commands' etc.. which point to arrays that must also be allocated!!). The ::draw function of your new class will have to use the allocated VGObject and no longer the frozen VGObject of the SVGDatabase. This way you can modify or replace elements of the original SVG as you wish, such as 'fillPaint', 'strokePaint', etc.
For my part, I used this method, but not to retrieve and modify an SVG from SVGDatabase, but to dynamically create the VGShape with their lists of 'commands' and 'points'... the syntax is relatively simple.

This way, I was able to create 'SVGLike' objects that I can easily use either directly on the screen or by rendering them in a dynamic bitmap by adding them to a 'Container' and calling 'drawToDynamicBitmap'.

To complete the story, in my case I have a multi-tasking system and I wanted to use 'drawToDynamicBitmap' to prepare images in a background process... but there is an annoying limitation in TouchGFX... you can't use the library's drawing functions anywhere other than in the task in which TouchGFX is running :( .. If you do it anyway, in the best case you get flickering on the screen because pieces of the bitmap you are busy building in the background end up in the frame buffer... and in the worst case it's a deadlock between the graphics task and your background task. I don't quite understand why graphics functions absolutely have to use the frame buffer but the library seems to be written that way. So your background task may build VGObject's and VGShape's but the rendering in the dynamic bitmap must be called inside the graphic task !! 

The drawback, if the bitmap rendering takes too much time, is that the refresh rate is slowed down. That's mainly visible in animations ... one trick to temper this is to call 'setFrameRateCompensation(true)' somewhere in the init code