设置correctOrientation:true,然后解决图像旋转问题并设置缩略图 - 但图像路径为:file://storage/emulated/0/Android/data/com.examole.helloworld/modified.jpg?149028394994
如果没有correctOrientation:true,则图像路径为:file:///storage/emulated/0/DCIM/Camera/1490345556009.jpg
尝试使用correctOrientation设置另一个图像时:true,则不会设置最新选择的图像。 以下是您的参考代码:
navigator.camera.getPicture(captureSuccess, onFail, {quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true,
allowEdit: true
});
先谢谢。
答案 0 :(得分:1)
You can try this,
$(document).on('click','.capture_photo',function(){
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.PNG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
});
});
// to call the success function of capture image(onPhotoDataSuccess)
function onPhotoDataSuccess(imageData) {
sessionStorage.setItem("img_api",imageData);
$('#captureimg').attr('src','data:image/jpeg;base64,' + imageData);
App.show_toast("Profile image updated successfully!");
}
//onfail
onFail(message) { alert('Failed because: ' + message); }
答案 1 :(得分:1)
我已经解决了这个并发布了我的答案
navigator.camera.getPicture(captureSuccess, onFail, {quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true,
});
var captureSuccess = function(mediaFiles) {
var fD = mediaFiles;
window.resolveLocalFileSystemURI(fD, function(fileEntry) {
fileEntry.file(function(fT) {
var fname = fileEntry.nativeURL.substr(fileEntry.nativeURL.lastIndexOf('/') + 1);
fileTransferUpload(fD,fname);
}, function() {
console.log('error');
});
}, onFError);
};
上面的方法fileTransferUpload只会在src中设置图像路径。
成功回调函数,接收到图像路径,并且没有从此路径获取nativeURL,我已在src中设置路径本身。
答案 2 :(得分:1)
这是一个更好的解决方案(涉及挖掘一些Java文件,但需要大约8秒)
在CameraLauncher.java中(在cordova-plugin-camera / src / android文件夹中)
//Old:
String modifiedPath = getTempDirectoryPath() + "/modified"+".jpg";
this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis());
AKA只是在文件名中移动时间戳。
//New:
String modifiedPath = getTempDirectoryPath() + "/modified"+ System.currentTimeMillis() +".jpg";
this.callbackContext.success("file://" + modifiedPath);
答案 3 :(得分:0)
document.addEventListener("deviceready",onDeviceReady,false);
var pictureSource; // picture source
var destinationType; // sets the format of returned value
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
抱歉,您想要添加此代码。