working with camera and imaging on nokia asha software platform 1.0
DESCRIPTION
Your camera and imaging apps can do more than before with Nokia Asha software platform 1.0, because of new APIs and increased available memory. Imaging apps for the Nokia Asha 501 phone can take full advantage of its 3.2-megapixel camera, in part because of the phone’s support for memory cards of up to 32 GB, a Java™ heap of 3 MB, and a maximum JAR size of 5 MB. In this webinar, Java expert Michael Samarin of Futurice introduces new Nokia Asha software platform 1.0 APIs for image scaling and image processing. He reviews related Java APIs that were made available on the Series 40 platform. In coding demonstrations, he provides detailed guidelines for capturing and processing images. Find out more about: * developing for Nokia Asha at: http://www.developer.nokia.com/Develop/asha * details on using advanced multimedia features in the Java Developer’s Library http://developer.nokia.com/Resources/Library/Java/#!developers-guides/multimedia/using-advanced-multimedia-features.html * details on using the Image Scaling API in the Java Developer’s Library http://developer.nokia.com/Resources/Library/Java/#!developers-guides/ui-graphics-and-interaction/image-scaling-api.html Check out the current webinar schedule here: http://www.developer.nokia.com/webinars or at http://developer.nokia.com/Develop/asha/learning/TRANSCRIPT
Michael Samarin Director, Developer Training and Evangelism Futurice @MichaelSamarin
WORKING WITH CAMERA AND IMAGING ON NOKIA ASHA SOFTWARE PLATFORM 1.0
3RD PARTY CAMERA AND IMAGING APPS ON ASHA 501
• Capture low resolution still images and record video with Mobile Media API (JSR-135);
• Downscale JPEG images with Nokia Image Scaling API;
• Apply image processing filters with Advanced Multimedia Supplements API (JSR-234);
• Access and change pixel data of images with LCDUI;
MOBILE MEDIA API (JSR-135)
• 3rd party Apps on Asha 501 support:
• Live camera viewfinder on LCDUI Form or Canvas;
• Still image capture: 320x240 JPEG (device and emulator in Asha SDK 1.0);
• Video capture: 320x240 MP4 (device);
IMAGE AND VIDEO CAPTURE WITH MM API
Manager
Player Control Data Source
javax.microedition.media
URLs “capture://image” “capture://video”
Live viewfinder VideoControl RecordControl
DISPLAYING LIVE CAMERA VIEWFINDER
Form videoForm; Item videoItem; Player player; VideoControl videoControl;
player = Manager.createPlayer("capture://image"); //player = Manager.createPlayer("capture://video"); player.prefetch(); player.realize(); player.start(); videoControl = (VideoControl)player.getControl("VideoControl"); videoItem = (Item)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null); videoForm.append(videoItem);
TAKING AND SAVING SNAPSHOT
byte[] imageBytes = videoControl.getSnapshot(null); Image image = Image.createImage(imageBytes, 0, imageBytes.length); ImageItem imageItem = new ImageItem("", image, Item.PLAIN, ""); videoForm.append(image); String fileName = System.getProperty("fileconn.dir.photos”) + "CapturedImage.jpg"; FileConnection file = (FileConnection) Connector.open(fileName, Connector.READ_WRITE); if (!file.exists()) file.create(); OutputStream out = file.openOutputStream(); out.write(imageBytes); out.close(); file.close();
RECORDING VIDEO
RecordControl recordControl; recordControl = (RecordControl)player.getControl("RecordControl"); recordControl.setRecordLocation(System.getProperty("fileconn.dir.photos”) + "CapturedVideo.mp4"); recordControl.startRecord(); ... ... recordControl.stopRecord();
HANDS-ON DEMO
– Displaying live camera viewfinder;
– Taking snapshot;
– Recording video;
NOKIA IMAGE SCALING API
• The Image Scaling API allows MIDlets to downscale images by file size or by dimension (i.e. width and height) with the aspect ratio of the image can be retained if required. For JPEG images, the output quality can be set before downscaling.
• Actual downscaling process is done outside of JVM, so no extra memory requirements for 3rd party apps.
• Note: The Image Scaling API cannot upscale an image, and does not allow users to select any protected images for downscaling due to security or copyright issues.
• Package com.nokia.mid.imagescale
USING IMAGE SCALING
• The Image Scaling API consists of the following classes and interfaces (packaged as a part of the Nokia API):
• ImageScaler
– Use the ImageScaler class to allow a MIDlet to downscale images in the device.
• ImageScalerConstants
– Use the ImageScaleConstants class to allow a MIDlet to use the image scaler definitions generated by the configuration utility.
• ImageScalerListener
– Use the ImageScalerListener interface to allow a MIDlet to discover status of images being downscaled in the device.
INITIATING IMAGE SCALING
ImageScaler imageScaler = new ImageScaler(sourceImageFilePath, destinationFilePath); imageScaler.addListener(this); Integer requestId = new Integer(imageScaler.scaleImage(newWidth, newHeight, true)); . . . public void scaleFinished(int requestId, int result) { ... }
IMAGE EFFECTS WITH AMMS (JSR-234)
• The Advanced Multimedia Supplements (JSR-234) on Asha 501 have possibility to apply several pre-defined image processing filters:
• Monochrome
• Negative
• Emboss
• Sepia
• Solarize
• API is asynchronous and allows register listeners to observe processing progress.
IMAGE EFFECTS WITH AMMS ON ASHA 501
MediaProcessor mediaProcessor = GlobalManager.createMediaProcessor(JPEG_TYPE); mediaProcessor.addMediaProcessorListener(this); ... mediaProcessor.setInput(inputStream, MediaProcessor.UNKNOWN); ... mediaProcessor.setOutput(byteArrayOutputStream); ImageEffectControl imageEffect = (ImageEffectControl) mediaProcessor.getControl( "javax.microedition.amms.control.imageeffect.ImageEffectControl"); imageEffect.setPreset("monochrome"); imageEffect.setEnabled(true); mediaProcessor.start(); ... public void mediaProcessorUpdate(MediaProcessor processor, String event, Object eventData){ ... }
HANDS-ON DEMO
– Nokia Image Scaling API
– Image Effects with APPS
THANK YOU!