Monica
Monica

Reputation: 389

I did a PhoneGap app that starts the camera, a picture is taken and saved to sdcard. How do I get that picture to show it in HTML?

I did a PhoneGap Android app that starts the camera, a picture is taken and saved to sdcard. The app shows the picture on the initial screen. The app also allows to navigate through some additional web pages. If I navigate away (to another web page) and come back to the first screen, the picture is no longer there. I tried to get it from the sdcard and show it using the HTML tag, to be seen even before another picture is taken, but the picture is not shown (I see the "alt" text instead).

I am not sure whether my problem is clear, but I am ready to answer your questions to clarify it.

My project is in the GitHub at the address https://github.com/monicamarcus/Android_PhoneGap

Anyone can help me? Thanks!

The Javascript that shows the picture the first time:

//Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
 var smallImage = document.getElementById('cameraPic');
smallImage.style.display = 'block'
smallImage.src = "data:image/jpeg;base64," + imageData;
}

Upvotes: 0

Views: 438

Answers (1)

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11717

Try this:

   function onPhotoDataSuccess(imageData) { 
    localStorage.img="data:image/jpeg;base64,"+imageData;
    var smallImage = document.getElementById('cameraPic');
   smallImage.src= localStorage.img;
   smallImage.style.display = 'block'; 
   }



document.addEventListener('deviceready',function(){
if(typeof(localStorage.img)!='undefined'){
smallImage=document.getElementById('cameraPic');
smallImage.src=localStorage.img;
smallImage.style.display='block';
}
},false);

Upvotes: 1

Related Questions