나는 몇 가지 문제에 대해 여기에서 물어보고 싶습니다.이미지 파일로 안드로이드에 sd 카드에 파일을 작성
PhoneGap을 사용하여 사진을 찍은 다음 사진을 캔버스에 표시 할 수있는 응용 프로그램을 만듭니다. 캔버스의 drawimage 이후에 캔버스를 이미지 파일로 변환하는 방법을 사용합니다. 하지만 Android의 SD 카드에 이미지 파일로 파일을 쓰는 것과 관련된 문제가 있습니다. 즉, SD 카드에서 생성 된 이미지 파일을 읽을 수 없습니다 (이미지가 유효하지 않습니다). 여러분의 도움과 제안에 대한
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);
}
나는 감사하고 :
여기 내 코드입니다.
캔버스로 캡처 한 후에 이미지 편집 작업을하고 있습니까? – amorbytes