Note that there are some explanatory texts on larger screens.

plurals
  1. POWrite file to sd card in android as image file
    primarykey
    data
    text
    <p>I would like to ask you here about some problem.</p> <p>I am using Phonegap to build an application that can take photo and then show the picture in a canvas.After drawimage in the canvas, I use a method to convert canvas to image file. But I have a problem related to writing file as image file to SD Card in Android,i.e, I cannot read the image file that was created in SD Card (image is invalid).</p> <p>Here is my code:</p> <pre><code>var picture = ""; function takePhoto() { navigator.camera.getPicture(onCameraSuccess, onCameraError,{ quality : 50, destinationType : Camera.DestinationType.FILE_URI //saveToPhotoAlbum: true }); } function onCameraSuccess(imageURL) { var canvas = document.getElementById('myCanvas'); var ctx=canvas.getContext("2d"); var imageObj = new Image(); imageObj.onload = function() { ctx.drawImage(imageObj, 0, 0,220,180); }; imageObj.src=imageURL; picture = imageURL; } function onCameraError(e) { console.log(e); navigator.notification.alert("onCameraError: " + e +" (" + e.code + ")"); } function storePhoto() { movePic(pictures); } function movePic(){ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("test.PNG", {create: true, exclusive: false}, gotFileEntry, fail); } function gotFileEntry(fileEntry) { fileEntry.createWriter(gotFileWriter, fail); } function gotFileWriter(writer) { var c = document.getElementById('myCanvas'); var img_from_canvas=c.toDataURL("image/png"); // base64 encoded var pic = img_from_canvas.split("base64,"); var pictures =window.atob(pic[1]); // decode base64 writer.write(pictures); alert("Your picture was successfully stored !") } function fail(error) { console.log(error.code); } </code></pre> <p>I am appreciated for your helps and suggestion.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload