Taking photos

Taking photo snapshots requires that you first create a Player for the capture action. Now you can realize the Player and get a VideoControl from your Player's instance. In your application, you need to specify a locator that is supported by your target device or platform. Supported Player locators were discussed in section Recording Sound and Video.

VideoControl has a method, getSnapshot, which allows you to get a snapshot of the video it is displaying. This is particularly useful when it is displaying live video from the device's camera, since it allows you to take a photo. The following is a code sample of how to take a photo using default settings:

byte[] pngImageData = videoControl.getSnapshot(null);

You can also specify other formats if the device supports them, and give a width and height:

videoControl.getSnapshot("encoding=bmp"); // BMP, default size

videoControl.getSnapshot("width=80&height=60"); // default encoding, size 80x60

videoControl.getSnapshot("encoding=bmp&width=80&height=60"); // BMP, 80x60

If values are specified for width and height, both of them must be specified, not just the width or height. In this case, the image is scaled to the requested width and height. If the requested aspect ratio (that is, 4:3) does not match that of the default size (in most devices 160 x 120), the resulting image will be distorted, or in Series 40 devices, if the width and height do not match a supported size, the closest match is used instead. The maximum size that can be captured depends on the free heap memory available. The system property video.snapshot.encodings contains a list of the valid video snapshot encodings for your device. 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.

For a complete example of a MIDlet that takes photos using this method, see document Camera MIDlet: A Mobile Media Example.