Created
January 24, 2016 07:44
-
-
Save jsbain/389a67c5aacb097b87fd to your computer and use it in GitHub Desktop.
canvas_save.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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