Skip to content

Instantly share code, notes, and snippets.

@jsbain
Created January 24, 2016 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbain/389a67c5aacb097b87fd to your computer and use it in GitHub Desktop.
Save jsbain/389a67c5aacb097b87fd to your computer and use it in GitHub Desktop.
canvas_save.py
# coding: utf-8
from objc_util import *
import canvas
import os
def save_canvas_to_png(filename):
rootVC = UIApplication.sharedApplication().keyWindow().rootViewController()
image=rootVC.accessoryViewController().consoleViewController().canvasImageView().image()
if image:
data=ObjCInstance(c.UIImagePNGRepresentation(image))
data.writeToFile_atomically_(os.path.abspath(filename),True)
else:
print 'canvas was empty'
if __name__=='__main__':
#Draw a red circle filling the entire canvas
import canvas
w = h = 512
canvas.set_size(w, h)
canvas.set_fill_color(1, 0, 0)
canvas.fill_ellipse(0, 0, w, h)
save_canvas_to_png('canvas.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment