Reputation: 301
How do I decode svg image from buffer? I know SVGs are just text but I don't know how to parse them to Magick::Image other than reading from disk.
#include <Magick++.h>
#include <stdio.h>
using namespace Magick;
int main() {
printf("EnableOpenCL ret: %d\n", Magick::EnableOpenCL());
Magick::Image svgImage;
svgImage.read("input.svg"); // first read file
svgImage.magick("png"); // then specify PNG format
svgImage.write("output.png");
return 0;
}
Upvotes: 0
Views: 235
Reputation: 24439
You would copy the buffer into Magick++'s Magick::Blob
and pass it to Magick::Image
constructor.
Magick::Blob svgData(memory_ptr, memory_length);
Magick::Image svgImage(svgData, svgRenderSize, "SVG");
Where memory_ptr
is the address of the svg data in memory, memory_length
is the total byte size of memory_ptr
, and svgRenderSize
is Magick::Geometry
instances the image size.
Upvotes: 2