Drawing:
#Copyright (c) 2008 Pankaj Nathani
#Drawing on an image
#You can draw several shapes on images
import graphics, e32, appuifw
from math import pi
#Define the exit function
app_lock=e32.Ao_lock()
def quit():
app_lock.signal()
appuifw.app.exit_key_handler=quit
canvas=appuifw.Canvas()
appuifw.app.body=canvas
appuifw.app.screen="full"
#Line
canvas.line((30,40,170,15), 0)
e32.ao_sleep(1)
#Rectangle
canvas.rectangle((30,45,110,100), fill=0xCC55EE) #Draws a purple rectangle
e32.ao_sleep(1)
#Dot
canvas.point((200,180), (253,46,103), width=4)
e32.ao_sleep(1)
#Ellipse
canvas.ellipse((22,260,58,280), fill=0x339900)
e32.ao_sleep(1)
app_lock.wait()
Opening:
#Copyright (c) 2008 Pankaj Nathani
#Opening an image or creating a blank one
import graphics, e32, appuifw
#Define the exit function
def quit():
app_lock.signal()
appuifw.app.exit_key_handler=quit
canvas=appuifw.Canvas()
appuifw.app.body=canvas
#We open an existing picture
pic=graphics.Image.open("C:\\mypicture.jpg")
#And also make a blank one
img=graphics.Image.new((240,320)) #Remember to specify the appropriate size in pixels
canvas.blit(pic)
#Sets the background as the picture
#Wait 5 seconds
e32.ao_sleep(5)
canvas.blit(img)
#Sets the background to the blank image
app_lock=e32.Ao_lock()
app_lock.wait()
Editing an Image:
#Copyright (c) 2008 Pankaj Nathani
#Editing an image - resizing, transposing and saving
import graphics, e32, appuifw
#Define the exit function
def quit():
app_lock.signal()
appuifw.app.exit_key_handler=quit
canvas=appuifw.Canvas()
appuifw.app.body=canvas
#We open the image we want to edit
img=graphics.Image.open("C:\\pic.jpg")
#We define the functions that do the editing and saving, for the menu
def resize():
global img, canvas
newx, newy=appuifw.multi_query([u"Enter width", u"Enter hight"]) #Asks for the new size
img=img.resize((newx,newy))
canvas.blit(img)
def transpose():
global img, canvas
img=img.transpose(ROTATE_90) #Rotates by 90 degrees
canvas.blit(img)
def save():
global img
name=appuifw.query(u"Enter a name for the new image", "text")
img.save("C:\\"+name+".jpg")
#Set the application's menu
appuifw.app.menu=[(u"Resize", resize), (u"Transpose", transpose), (u"Save", save), (u"Exit", quit)]
#Display the image
canvas.blit(img)
app_lock=e32.Ao_lock()
app_lock.wait()