Java Reference
In-Depth Information
If your camera phone has MMAPI support, you will be able to access it as a player using the
URL “capture://video”:
Player mPlayer = Manager.createPlayer("capture://video");
You can then obtain a VideoControl instance from the player. This VideoControl can be
used to show the live video on either a Canvas subclass or an Item within a form (shown in the
previous section). At any time, you can capture a still picture by calling the getSnapshot()
method of the VideoControl . You can specify a graphic format as a parameter (format supported
depends on implementation), or use null to obtain the default (always supported) PNG format:
byte[] rawImg = mVidc.getSnapshot(null);
The returned byte array contains the raw image. This byte array can be converted to an
Image using the call to Image 's static factory method:
Image image = Image.createImage(rawImg, 0, rawImg.length);
WTK 2.x Camera Simulation
When using an emulator from the Wireless Toolkit, camera support in MMAPI is performed via
simulated incoming video. The WTK does not support access to the underlying platform's
video capture capability. This simplifies WTK maintenance and allows MMAPI snapshots to
work over any platform, with or without camera support.
The simulated incoming video has a moving grid, with a seconds counter on the top left.
This image ensures that every video frame is different from all the subsequent ones.
Listing 16-6 shows CameraMIDlet , which can be used to take snapshots using a camera phone.
Figure 16-6 shows CameraMIDlet running on the emulator, with simulated camera video. The
live video is displayed as an Item at the top of the form. You can click the Capture menu item,
and a picture of the live video will be snapped and displayed below the video using an ImageItem .
Figure 16-6. Capturing images using simulated video on the WTK emulator
 
Search WWH ::




Custom Search