How to work with camera in Icenium

Learn more about Icenium here

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"
 <button onclick="capturePhoto();">Capture Photo</button> <br>
 <img style="width:60px;height:60px;" id="smallImage" src="" />

On touch of Capture Photo button we are calling function capturePhoto().

function capturePhoto() {, onFail, {
 quality: 50,
 destinationType: destinationType.DATA_URL


In above function we are using cordova function 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.