memononen / nanosvg

Simple stupid SVG parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

insert SVG file to data buffer

OriBibi opened this issue · comments

After I got svg file(I hope it's ok the way I did it..) I want to convert the NSVGimage* to some buffer (like grayscale).

char* someSVGstring="<svg width=\"720\" height=\"576\"><text x='0' y='15' fill='red'>I love SVG Too!"</text></svg>";
struct NSVGimage* Image;
Image = nsvgParse(someSVGstring, "px", 96.0f);

//now, insert Image  to buffer

I dont need to show the picture, all I want is to get the image in buffer. can you help me to do that?

I was also thinking about storing NSVG struct data in a buffer and use that instead of an embedded SVG file in cases where I need embedded vector graphics.
Here's something I came up with (storing the NSVG data in a file however): https://gist.github.com/darealshinji/b857c8690e6919888300979d950ec15d
But it's messy and loading the data from the file doesn't work. Maybe you can make something out of it.

To convert the parsed svg to an raster image, an example rasterizer is availaibe in the file "nanosvgrast.h".

For a usage example, you may look to the git project TkSVG

Hope this helps,
Harald