Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to take a photo using PySymbian

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: camera
Created: cyke64 (15 Mar 2007)
Last edited: hamishwillee (31 May 2013)

Contents

Overview

This snippet shows how to take a photograph in Python.

Preconditions

Note: The camera module is not available for S60 1st Edition.

Note: The Image object method save is not available for S60 1st Edition.

Images can be saved in either JPEG or PNG format.

Source code

import appuifw, e32, camera
 
 
app_lock = e32.Ao_lock()
#Define the exit function
def quit():
#Close the viewfinder
camera.stop_finder()
#Release the camera so that other programs can use it
camera.release()
app_lock.signal()
appuifw.app.exit_key_handler = quit
 
#Function for displaying the viewfinder
def vf(im):
appuifw.app.body.blit(im)
 
#Function for taking the picture
def take_picture():
#Take the photo
photo = camera.take_photo('RGB', (1024, 768))
#Save it at maximum quality
photo.save(photo_savepath, quality = 100)
#Restart the viewfinder
camera.stop_finder()
camera.start_finder(vf)
 
photo_savepath = u"C:\\photo.jpg"
#This is the path and name for storing the photo
 
#Set the application's body to Canvas
appuifw.app.body = appuifw.Canvas()
 
#Start the viewfinder
camera.start_finder(vf)
 
#Set the application's menu with the option to take the photo
appuifw.app.menu=[(u"Take photo", take_picture)]
 
#Wait for the user to request the exit
app_lock.wait()

Postconditions

A photograph will be taken with the given settings and stored at the given path.

Additional information

The camera module has the following functions that are related to taking photos:

  • cameras_available()

Returns the number of cameras available in the device.

  • image_modes()

Returns the image modes supported in the device as a list of strings, for example: ['RGB12', 'RGB', 'JPEG_Exif', 'RGB16'].

  • image_sizes()

Returns the image sizes (resolution) supported in the device as a list of (x, y) tuples, for example: [(640, 480), (160, 120)].

  • flash_modes()

Returns the flash modes available in the device as a list of strings.

  • max_zoom()

Returns the maximum digital zoom value supported in the device as an integer.

  • exposure_modes()

Returns the exposure settings supported in the device as a list of strings.

  • white_balance_modes()

Returns the white balance modes available in the device as a list of strings.

The function used for taking pictures takes its optional parameters from the functions described above and has the following general form: take_photo([mode, size, zoom, flash, exposure, white_balance, position]), where position is the camera to be used, if the device has more than one (0 for normal camera, 1 for front camera).


On some devices, in order to use the maximum resolution available, special steps must be taken:

  1. Switch to the landscape mode.
  2. Import the camera module.
  3. Take the picture in the 'JPEG_Exif' format.
  4. Save it by writing its information in a file, not as an Image object.

Here is a code snippet for a device with a 5 megapixel camera, such as the Nokia N95:

import appuifw, e32
 
 
#Switch to landscape mode
appuifw.app.orientation = 'landscape'
 
import camera
 
app_lock = e32.Ao_lock()
#Define the exit function
def quit():
#Close the viewfinder
camera.stop_finder()
#Release the camera so that other programs can use it
camera.release()
app_lock.signal()
appuifw.app.exit_key_handler = quit
 
#Function for displaying the viewfinder
def vf(im):
appuifw.app.body.blit(im)
 
#Function for taking the picture
def take_picture():
#Take the photo
photo = camera.take_photo('JPEG_Exif', (2592, 1944))
#Save it
f = open(photo_savepath, "wb")
f.write(photo)
f.close()
#Restart the viewfinder
camera.stop_finder()
camera.start_finder(vf)
 
photo_savepath = u"C:\\photo.jpg"
#This is the path and name for storing the photo
 
appuifw.app.body = appuifw.Canvas()
 
#Start the viewfinder
camera.start_finder(vf)
 
appuifw.app.menu=[(u"Take photo", take_picture)]
 
#Wait for the user to request the exit
app_lock.wait()
This page was last modified on 31 May 2013, at 01:05.
34 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×