|

楼主 |
发表于 2016-11-21 17:59:26
|
显示全部楼层
谢谢,问题已解决,点击不同功能设置camera.getPicture的参数sourceType为相册或相机就可直接调用相应的功能,将返回的数据DATA_URL进行转换后即可实现,如下:
navigator.camera.getPicture(onLoadImageSuccess, onLoadImageFail, {
destinationType : navigator.camera.DestinationType.DATA_URL,
sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY,
quality : 80,
//targetWidth : 100,
//targetHeight : 100,
saveToPhotoAlbum : false
});
// 拍照成功后回调
function onLoadImageSuccess(imageData) {
localStorage.setItem("imageData", "data:image/jpeg;base64," + imageData);
var smallImage = $(self.getElementByXid('chooseImage'));
// 显示图像
var imgdata = "data:image/jpeg;base64," + imageData;
smallImage.src = imgdata;
var $image = $('.cropper-example-1 > img');
var blobURL = URL.createObjectURL(self.dataURLtoBlob(imgdata));
$image.one('built.cropper', function() {
URL.revokeObjectURL(blobURL); // Revoke when load complete
}).cropper('reset').cropper('replace', blobURL);
}
function onLoadImageFail(error) {
} |
|