Comments (3)
Basically, that std::vector<uint32>
is the pixel data of your raster image. so, you need to draw that raster image with cairo
.
To do that, you need to create a cairo image surface and the use it as source and draw with cairo_paint
.
The code would look something like that:
//Let's say you have the following variables assigned correct values
cairo_t *cr; //your cairo rendering context
std::vector<std::uint32_t> pixels; //pixel data you got from svgren::render(...)
unsigned imWidth, imHeight; //raster image width and height, obtained from svgren::render(...)
//Then draw the raster image to cairo context
//create image surface and initialize it with our pixel data
cairo_surface_t *imageSurface = cairo_image_surface_create_for_data(
reinterpret_cast<unsigned char*>(&*pixels.begin()), //pointer to pixel data
CAIRO_FORMAT_ARGB32, //data format is ARGB
imWidth,
imHeight,
imWidth * sizeof(std::uint32_t) //stride
);
//set the new image surface as source, dstX and dstY is where you want to draw the image
cairo_set_source_surface(cr, imageSurface, dstX, dstY);
//do the actual paint with current source
cairo_paint(cr);
//remove the surface if we don't need it anymore
cairo_surface_destroy(imageSurface);
I haven't tested the code, but it should give you the basic idea.
from svgren.
Thank you @igagis for the code sample!
from svgren.
Hope it helps :)
from svgren.
Related Issues (20)
- Image element not rendered HOT 5
- add <defs><style></style></defs> support HOT 8
- I can't link the release version after update to the new svgren version HOT 6
- Initial render very slow with protected software HOT 10
- Render SVG file by string HOT 1
- cocoapods svgren not found HOT 4
- utki cocoapod doesn't have a lib HOT 5
- Support for stroke-dasharray and stroke-dashoffset HOT 4
- Unresolved external symbol HOT 6
- Not correctly displaying shapes. HOT 8
- Pixel layout & console output HOT 5
- division by 0
- compiling errors after update to the latest version HOT 5
- add <pattern> support
- No Images loaded since last Update HOT 46
- VS2017 v141 toolset link failed HOT 6
- Problem rendering Instagram logo HOT 5
- XCFramework support HOT 10
- Tutorial needs update: requires C++/17 standard, not C++/11 HOT 2
- Artifact when drawing SVG with `circle` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svgren.