Forum Archive

Export Canvas button?

ExParrot

My scripts create graphs on canvas.
The canvas view screen no longer has the familiar export button! How do you export the full canvas (without UI controls obscuring the edges) to camera roll now?

brumm
canvas.draw_clipboard(x,y,width,height)
photos.save_image(clipboard.get_image())
ExParrot

@brumm :
Thanks! Now I have a good use for the new auto load feature. I'll make that a script called ExPortit(). 🤓

ExParrot

That snippet assumes the desired image is on (part of) the clipboard. I'll have to tweak it to use the whole canvas...

brumm

clipboard.get_image() doesn't return a PIL Image, it's returning None 🙁. So the Pythonista 1.5 way doesn't work.

ExParrot

Are you sure you had an image on the clipboard when you called clipboard.get_image()? (And how did you evaluate the return value?) Even if it works as advertised, we'd need a function to copy the current canvas to clipboard. (Why can't I even find that?) This is why I dread updates of my favorite apps.

ExParrot

canvas.draw_clipboard(0,0,scrSize[0],scrSize[1]) lets you draw on a copied image. What's its inverse?

JonB

i think scene or ui is intended to be sort of a replacement to canvas. Although not as convienent for doing interactive "turtle" style drawings, these do let you save.

What you are asking is possible via the new objc module. The UIImageView that represents the canvas is a sibling to the console output textview. It should be possible to grab the UIImage reference, and use UIImagePNGRepresentation to write out the png. I don't have time this morning tomwork on it, but in the next day or so. In the meantime, check out scene drawing, or ui.Path style drawing, which I think have many of the features you want.

ccc

@JonB couldn't you just use ui.ImageView.draw_snapshot() as you recommended in https://forum.omz-software.com/topic/2185/image-from-scene ?

brumm

Sorry, I think I mixed it up.

JonB

https://gist.github.com/389a67c5aacb097b87fd

Simply import this function, and run it after drawing to the canvas. see example.
It is not necessary to fill the canvas white- it is actually transparent, unless you have drawn to it (as should be obvious when you save an image then quickview it)