O'Reilly logo

PhoneGap by Andrew Lunny

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Saving pictures

Don't believe that we can do the same thing as above using raw image data? Okay, I'll prove it:

  1. Let's modify the longTouchHandler in a couple of key ways:
    function longTouchHandler(ele) {
        navigator.camera.getPicture(function (img) {
            try {
                  alert(img);
    x$(ele).top('<img src="data:image/png;base64,' + img +
    '">'); 
    			  } catch(e) {
                alert(e);
            }
        }, function (e) {
            alert('camera failure!');
        }, {
            quality: 50,
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
    destinationType: navigator.camera.DestinationType.DATA_URL		
    		});
    }

    There at the bottom, we've switched our destinationType—as you will note, we now want a DATA_URL.

    The other key point is the element we inserted looks a little different: instead of setting the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required