我已经尝试实现这项工作 1.拍摄照片 2.从保存的地方获取照片 3.将照片读取为 base64
我遵循了这种方法:
var cameraOptions = {};
function capturePhoto() {
console.log("capture photo");
cameraOptions = { quality: 70, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA, saveToPhotoAlbum: true };
doIt();
}
function doIt() {
navigator.camera.getPicture(onCameraSuccess, onCameraFail, cameraOptions);
}
function onCameraSuccess(imageURI) {
console.log("Camera Success");
$('#MokhalfaPhotoLocation').val(imageURI);
console.log("Image URI: " + imageURI);
window.resolveLocalFileSystemURI(imageURI, onResolveImageSuccess, onFail); //get the file from the physical path...
}
function onResolveImageSuccess(fileEntry) {
fileEntry.file(gotFile, onFail);
}
function gotFile(file) {
readDataUrl(file);
}
function readDataUrl(file) {
console.log("read file as dataUrl");
var reader = new FileReader();
reader.onloadend = function (evt) {
console.log("Read as data URL");
window.localStorage.setItem("mokhalfaPhotoURL", evt.target.result);
};
reader.readAsDataURL(file);
}
这条链在 CameraSuccess 之前工作正常,然后它就失败了
window.resolveLocalFileSystemURI(imageURI, onResolveImageSuccess, onFail);
它进入了 onFail 事件,错误代码 = 5
顺便说一句,这段代码在 Android 上运行良好,但问题出在 Windows Phone 7 上,有人知道问题出在哪里吗?