Aquan1111
Aquan1111

Reputation: 65

How to save a kivy canvas object as an image file

I was wondering if it is possible to save a canvas that had several textures painted on it as an image file.

I know I can save regular Image's (kivy.core.image) or Texture's (kivy.graphics.texture) as an image file with the save() function, so if I am able to convert the canvas to an Image or a Texture it should be easy, but so far I wasn't able to do this.

Upvotes: 3

Views: 2864

Answers (2)

John Anderson
John Anderson

Reputation: 39052

The problem is that your MyPainter widget has its default size of (100,100) and its default position (0,0). So it is actually behind your Save Button. So all your drawing is actually outside the MyPainter widget, and saving the widget to an image is blank.

The fix is to change the pos and size of MyPainter, and perhaps use collide_point() in your on_touch_down() and on_touch_move() methods to ensure that you are actually drawing on the MyPainter widget.

Upvotes: 0

inclement
inclement

Reputation: 29488

Widgets have an export_to_png method. Call this from the Widget whose canvas you have drawn on.

Upvotes: 10

Related Questions