Sign up

Creating Pixbufs of SVG data

I want to create a Pixbuf from SVG data read at compile time. It is easy to load a file at run time, but that means installing the file. Most GTK builder constructors for menus and UIs have a way of using immediate string data, but the GDK Pixbuf appears not to have such a thing – unless I just missed it?

Has any found a way of loading SVG images into a Pixbuf using immediate data from compile time (i.e. a string import of an SVG file)?

Re: Creating Pixbufs of SVG data

On 8/25/18 10:16 PM, Russel Winder wrote:

I want to create a Pixbuf from SVG data read at compile time. It is easy to load a file at run time, but that means installing the file. Most GTK builder constructors for menus and UIs have a way of using immediate string data, but the GDK Pixbuf appears not to have such a thing – unless I just missed it?

Has any found a way of loading SVG images into a Pixbuf using immediate data from compile time (i.e. a string import of an SVG file)?

You have two options to load the SVG form a string:

Using rsvg.Hande:

Handle img = new Handle(cast(ubyte[])yourSVG);
Pixbuf pixbuf = img.getPixbuf();

or use gdkpixbuf.PixbufLoader:

PixbufLoader loader = new PixbufLoader();

loader.write(cast(char[])yourSVG);

loader.close();

Pixbuf pixbuf = loader.getPixbuf();

Re: Creating Pixbufs of SVG data

I had not realised that SVG could be parsed from a char[]. Rather silly of me. The PixbufLoader route seems the right one for me I think – unless I am wrong, :-)

Re: Creating Pixbufs of SVG data

PixbufLoader loader = new PixbufLoader();

I tried gdkpixbuf.PixbufLoader but it seems (in 3.8.3) not to have a this() constructor.

Re: Creating Pixbufs of SVG data

On Sun, 26 Aug 2018 17:38:37 GMT, Russel Winder wrote:

PixbufLoader loader = new PixbufLoader();

I tried gdkpixbuf.PixbufLoader but it seems (in 3.8.3) not to have a this() constructor.

Forget this, failure of the wetware to actually read what was wrong.

Re: Creating Pixbufs of SVG data

Now the issue is to get the SVG image sized to a bigger size than the default.

Re: Creating Pixbufs of SVG data

Use setSize on the PixbufLoader before getting the Pixbuf.

Easy really when you read the manual. :-)