In Series 40, use capture://image.
To take photos with the device camera:
Create a Player for capturing image from the device camera, and initialize the Player.
Player player; player = Manager.createPlayer("capture://image"); player.realize(); player.prefetch();
For more information about video recording locators, see section Recording Sound
Display the video input by creating a VideoControl for the Player, and start the Player. The user can now see a live video feed from the device camera.
VideoControl videoControl; videoControl = (VideoControl)player.getControl("VideoControl"); if (videoControl != null) { videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas); videoControl.setVisible(true); player.start(); }
Take a snapshot of the video input by calling the getSnapshot method of the VideoControl object. The following code snippet takes a snapshot in the default format.
byte[] pngImage = videoControl.getSnapshot(null);
You can also specify the image format and resolution for snapshots. For example:
videoControl.getSnapshot("encoding=image/jpg"); // JPG format with default resolution videoControl.getSnapshot("width=640&height=480"); // default format with 640 x 480 pixel resolution videoControl.getSnapshot("encoding=image/jpg&width=640&height=480"); // JPG format with 640 x 480 pixel resolution
For more information about defining image formats and resolutions for snapshots, see the following sections on this page.
Use the snapshot. For example, depending on the purpose of your MIDlet, you can save the snapshot in a record store for later use, send it to a server over an HTTP connection, or display it on the device screen as an Image.
If you do not want to use the default image format for snapshots, specify a different image format by using the encoding parameter:
videoControl.getSnapshot("encoding=<format suffix>");
For example, to take a snapshot in the BMP format:
videoControl.getSnapshot("encoding=bmp");
Supported image types can be, for example, encoding=png, encoding=bmp, encoding=jpeg, and encoding=gif. JPEG format is the most compact format. The use of compact format reduces memory usage, and is therefore recommended in many cases. To find out which image formats are supported by the device, use the video.snapshot.encodings system property:
String supportedFormats = System.getProperty("video.snapshot.encodings");
You can define image color as a RGB colored image or a Grayscale Image. For example: color=gray8 or color=gray16.
JPEG images have a quality parameter that is defined as an integer between 10 and 100.
You can also specify width and height of the image. The following string specifies the resultant image with JPEG image format, width of 4000, height of 3000 and quality of 100.
video.Control.getSnapshot(“encoding=jpeg&width=4000&height=3000&quality=100”);
Compatible sizes
When using non-default image sizes, the behavior of getSnapshot depends on the dimensions requested. If the requested image falls into platform compatible size it is directly obtained and returned to the user.
For a complete example of a MIDlet that takes photos using this method, see document Camera MIDlet: A Mobile Media Example on Nokia Developer.
For additional examples, see the following articles in the Nokia Developer Wiki: