sammycage / plutovg

Tiny 2D vector graphics library in C
MIT License
324 stars 31 forks source link

How to draw a image on surface? #37

Closed tktkku closed 2 weeks ago

tktkku commented 2 weeks ago

I want to draw a image, in a memory buffer, on the surface. With these lines I got a white area.

// initial
plutovg_surface_t* surface = plutovg_surface_create(width, height);
plutovg_canvas_t* canvas = plutovg_canvas_create(surface);
plutovg_canvas_save(canvas);
plutovg_canvas_set_rgb(canvas, 1, 1, 1);
plutovg_canvas_paint(canvas);
plutovg_canvas_restore(canvas);

// draw lines and curves...

// try to draw image on surface
plutovg_surface_t* s = plutovg_surface_load_from_image_data(image->data, image->data_len);
plutovg_surface_write_to_jpg(s, filename, 100); // the image read correctly

plutovg_matrix_t m;
plutovg_matrix_init_identity(&m);
plutovg_canvas_set_texture(canvas, s, PLUTOVG_TEXTURE_TYPE_PLAIN, 0.5, &m);
plutovg_canvas_set_operator(canvas, PLUTOVG_OPERATOR_SRC);
plutovg_canvas_paint(canvas);
plutovg_surface_destroy(s);
// The area that was supposed to be an image is now blank
plutovg_surface_write_to_png(surface, "test.png"); 

There was a similar issue before, but the API has changed so much that I'm not sure this is the right way to do it. Can you give me some advice, please?

sammycage commented 2 weeks ago

Thank you for bringing this up! The API has indeed undergone significant changes, and to better assist you, it would be helpful to see the complete code you were using with the previous API. Could you please share the code so I can understand exactly what you're trying to achieve? If you'd prefer, you can also send it to me via email if you're unable to share it here. Looking forward to your response!

tktkku commented 2 weeks ago

Thank you for your reply. After more testing, it shows that these actually work fine. It's not about plutovg. It was something else that was affecting the output. Sorry to bother you. I'll close this issue.