Retrieving thumbnail of an image taken with a PS 2.0 Camera API
This article explains how to retrieve thumbnail of an image taken with a PS 2.0 Camera API
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Overview
Platform Services (PS) 2.0 Camera API can be used to take an image by using device’s native camera application. However the captured image is not suitable to be used in widgets native size, as it is simply too large to be presented. PS 2.0 offers an API to solve this problem. Media Management API has getThumbnail() method which can retrieve an thumbnail image of the captured image.
Taking picture
Taking picture, with the PS 2.0 Camera API is straightforward. In the success-callback handler, we pass the URI of the captured image, to getThumb() method. Please note that PS 2.0 Camera API has issues with Non English devices. In addition there is a change in handling widget.onshow event, in WRT 7.3 (Browser 7.3). Please use tweaked platformservices.js file, from attached example application, to address these problems. Also See Managing Platform Services 2.0 permissions prompts to how to reduce amount of prompts shown to the user.
var camera_so;
function camera_takePicture_error_callback(err){
alert("Error Code:" + err.code + " Error Message:" + err.message);
}
function camera_takePicture_callback(picture_array){
//actually in case of success, the lenght of the array is 1, no more
for (var i = 0; i < picture_array.length; i++) {
getThumb(picture_array[i].uri);
}
}
/**
* Takes a picture with a native camera application
*/
function camera_takePicture(){
try {
camera_so = nokia.device.load("camera");
//launch native camera application and retreive the captured image
var transactionID = camera_so.startCamera(camera_takePicture_callback, camera_takePicture_error_callback);
}catch (e) {
alert(e);
}
}
Get Thumbnail
Thumbnail image is obtained by using PS 2.0 Media management API. One important aspect to note is, file URI returned by Camera API, has preceding file:///, where as Media Management API expects file://. Thumbnail retrieving is demonstrated in the code below.
// ErrorCallback function
function errorCB(err){
alert("ErrorCode: " + err.code + " ErrorMessage: " + err.message);
}
// callback function
function showThumb(uri){
document.getElementById("photo").src = uri;
}
/**
* Extracts thumbnail from image, taken with a camera
*/
function getThumb(image_uri){
try {
thumbso = nokia.device.load("media");
alert(image_uri);
// strip file:/// and replace with file://
image_uri = image_uri.substring(8, image_uri.length);
image_uri = "file://"+image_uri;
//define thumbnail size
var thumb={
uri: image_uri,
size:{
width: 200,
height: 150
}
}
var transactionId = thumbso.getThumbnail(showThumb, thumb, errorCB);
}
catch(e) {
alert(e);
}
}


(no comments yet)