Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API
Java-enabled devices are rapidly evolving into full-fledged multimedia platforms. Features once available on separate devices such as cameras, radios, and audio processing are now being combined. Currently the developer must program to many different operating systems and APIs to take advantage of these advanced multimedia features—but that is about to change.
In this article, I present an overview of the Advanced Multimedia Supplements Specification (AMMS), explaining how it fits with the other APIs available on J2ME, and giving a series of code samples demonstrating some of the new features.
The AMMS builds on the Mobile Media API for J2ME (MMAPI) and therefore inherits the concepts of Players, to play both sound and video; the Manager, to create Players; and Controls, to interact with the various types of Players. AMMS adds many new Controls and also a GlobalManager, which creates new objects for the effects network and image processing functionality. It is a small-footprint API targeted
for J2ME devices running Connected Limited Device Configuration (CLDC) or Connected Device Configuration (CDC), and profiles such as the Mobile Information Device Profile (MIDP). You can download the public review draft of the specification from the Java Community Process Website.
AMMS implementations consist of five building blocks, or capabilities:
At least one of these capabilities must be supported for a device to be "AMMS-compliant." Each of these capabilities defines the programming artifacts available to the developer, some of which are mandatory and some optional ("must" and "may" are used throughout the rest of this article to indicate this). Of course, the devices running this software will vary greatly in the level of sophistication they offer—think of all the kinds of mobile phones you can buy—so the developer will have to design the program to cope with what is available. The following sections describe these five capabilities and show some of the interfaces and methods available.
Although you can take a picture with the MMAPI's VideoControl, AMMS gives you much more control over the way the picture is taken and what is done with it—think digital camera. In the
examples that follow, I have already created a Player using Manager.createPlayer("capture://video"). Here we use the CameraControl (which must be supported in this capability) to enable the audio/visual shutter feedback, check if the camera is rotated
to be in portrait mode (some advanced devices may be able to tell which way the camera is facing), and then allow the user
to choose an exposure mode and image resolution:
CameraControl camera = (CameraControl)
player.getControl("javax.microedition.media.control.camera.CameraControl");
camera.enableShutterFeedback(true);
int rotation = camera.getCameraRotation();
boolean portrait = false;
if(CameraControl.ROTATE_LEFT==rotation ||
CameraControl.ROTATE_RIGHT==rotation)
portrait = true; // And then perhaps do something different with the image
String[] exposureModes = camera.getSupportedExposureModes();
camera.setExposureMode(exposureModes[2]); // Pick one
int[] resolutions = camera.getSupportedStillResolutions();
camera.setStillResolution(1); // Pick the second pair (w, h)
We can also set the flash to the mode we want using FlashControl (which must be supported). AMMS contains a predefined list of modes, some or all of which may be available. Here we assume
that auto with red-eye reduction is in the list of modes:
FlashControl flash = (FlashControl)
player.getControl("javax.microedition.media.control.camera.FlashControl");
int[] modes = flash.getSupportedModes();
flash.setMode(FlashControl.AUTO_WITH_REDEYEREDUCE);
White balance can be changed using WhiteBalanceControl (which may be supported). The presets available depend on the device:
if((WhiteBalanceControl white = (WhiteBalanceControl)
player.getControl("javax.microedition.media.control.camera.WhiteBalanceControl"))
!= null) {
String[] presets = white.getPresetNames();
white.setPreset("tungsten"); // Picked from list
int kelvin = white.getColorTemp(); // for display to user
}
We can zoom in to frame the subject using ZoomControl (which may be supported if the camera has a zoom function). We can use optical and digital zoom if they are available. The
zooms have a set of levels that they can be set to, and, since our base configuration is CLDC 1.0, we use ints to represent
fractions—100 means 1x, 150 means 1.5x, etc. Here we find out what levels are available, choose one, and zoom in by one level:
if((ZoomControl zoom = (ZoomControl)
player.getControl("javax.microedition.media.control.camera.ZoomControl"))
!= null) {
int max = zoom.getMaxOpticalZoom(); // e.g., 200 for 2x
int levels = zoom.getOpticalZoomLevels(); // e.g., 3 levels - 1x, 1.5x and 2x
zoom.setOpticalZoom(140); // Request the closest level to 1.4x, which will be 1.5x
zoom.setOpticalZoom(ZoomControl.NEXT); // Zoom in to 2x
}
To manually set the exposure settings, we can use ExposureControl (which may be supported). Again we use ints to represent fractions—an f-stop of 280 means f2.8. Since changing the optical
zoom can affect the f-stop, we should set the f-stop after changing the zoom (f-stop measures the size of the aperture on
a lens; the numbers get smaller as the aperture gets bigger):
if((ExposureControl exposure = (ExposureControl)
player.getControl("javax.microedition.media.control.camera.ExposureControl"))
!= null) {
exposure.setExposureTime(2); // Microseconds (1/500th second)
exposure.setFStop(280);
exposure.setISO(200);
}
We can focus using the FocusControl (which must be supported):
FocusControl focus = (FocusControl)
player.getControl("javax.microedition.media.control.camera.FocusControl");
if(focus.isAutoFocusSupported()) {
focus.setFocus(FocusControl.AUTO);
} else {
// Otherwise, try the "mountain" or infinity setting. Find out what was actually set.
int focusSet = focus.setFocus(Integer.MAX_VALUE);
}
Now we can take a photo or a series of photos in burst-shooting mode. PlayerListener from MMAPI can be used to listen for shooting events if we want to initiate shooting and then immediately continue processing
in this thread, or if we want to give the user the option of previewing the picture. (Note: VideoControl from MMAPI can also be used but is not as sophisticated.) Here we set up the filename(s) to be saved and then either take
up to 20 pictures in burst mode, or take one and allow the user to keep or discard it:
| Subject | Replies |
Last post
|
|
By JavaWorld
|
4 |
05/16/08 06:28 AM
by Anonymous |
|
By |
0 |
04/22/08 06:02 AM
by Anonymous |
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq