memononen / nanosvg

Simple stupid SVG parser
zlib License
1.71k stars 363 forks source link

insert SVG file to data buffer #190

Open OriBibi opened 3 years ago

OriBibi commented 3 years ago

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?

darealshinji commented 3 years ago

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.

oehhar commented 3 years ago

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

darealshinji commented 3 years ago

example2.c is a good starting point: https://github.com/memononen/nanosvg/blob/master/example/example2.c