In this post we will take a look on working with camera in Icenium. You can access camera in Icenium using Cordova or PhoneGap.
Let us say we want to capture a photo on touch of a button. I have designed view as below. On touch of button camera will be launched and then taken photo will get bind to image control.
<div id="home" data-role="view" data-title="Share"> <button onclick="capturePhoto();">Capture Photo</button> <br> <img style="width:60px;height:60px;" id="smallImage" src="" /> </div>
On touch of Capture Photo button we are calling function capturePhoto().
function capturePhoto() { navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL } ); }
In above function we are using cordova function navigator.camera.getPicture() to launch camera and click photo. You can pass many optional parameters to this function like quality, destinationType, sourceType, targetWidth , targetHeight etc.
On successful selection of photo onPhotoDataSucess function will be called. In this function you can access photo and use that as per your required. In this scenario we are binding that too an image control.
function onPhotoDataSuccess(imageData) { var smallImage = document.getElementById('smallImage'); smallImage.src = "data:image/jpeg;base64," + imageData; }
As you see that we are reading image with data url and setting that as source of image. If there is error selecting photo then onFail() function will be called. We can simply display an error message in this function.
function onFail(message) { alert('Failed because: ' + message); }
In this way you can work with camera in Icenium. I hope you find this post useful. Thanks for reading.