Namespaces
Variants
Actions
Revision as of 03:35, 19 September 2012 by hamishwillee (Talk | contribs)

Archived:How to edit an image in PySymbian

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia N96

Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition

Article
Keywords: graphics, image
Created: bogdan.galiceanu (28 Mar 2008)
Last edited: hamishwillee (19 Sep 2012)

Overview

This article describes how to manipulate images in PySymbian.

Code snippet

import appuifw, e32
from graphics import *
 
#Define the exit function:
app_lock=e32.Ao_lock()
def quit():app_lock.signal()
appuifw.app.exit_key_handler=quit
 
#We open the image
img=Image.open("C:\\i.jpg")
 
#We can see its current size
print img.size
 
#Now we resize it:
img=img.resize((240,240), keepaspect=0)
#The target size is a tuple containing the new dimensions in pixles
#keepaspect is optional. If 1, the image's current aspect ratio is maintained
 
#The image can also be transposed (here we rotate it by 90 degrees)
img=img.transpose(ROTATE_90)
#Other ways of transposing are:
#FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_180, ROTATE_270
#Note that rotations are counterclockwise
 
#Finally, we save the new image
img.save("C:\\i2.jpg", quality=100)
 
#Tell the application not to close until the user tells it to:
app_lock.wait()

Postconditions

Here is the result for the example above:


InitialImg.jpg          FinalImg.jpg

The initial image                                                                                                               The resulting image


See also: How to add a text to an image

126 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved