在ionic应用程序中,我想拍一张照片,然后在图像中显示出来。
$scope.takePicture = function () {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 640,
targetHeight: 640,
mediaType: Camera.MediaType.PICTURE,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function (imageData) {
var image = document.getElementById('myImage');
image.src = imageData;
})
}在ios上一切正常,在我的应用程序中,我看到了
在Android上,我什么也没看到!但是图像是正确保存的,因为我可以在我的服务器上发送图像文件而不会出现问题。
我试着补充一下:
<allow-navigation href="file:*"/>在我的config.xml中,我添加了:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *; img-src 'self' data: file: *"> 在我的index.html中,为了保证“file:”下的图像安全:
但是,再一次,没有结果。
有什么帮助吗?
马西莫
发布于 2016-07-24 08:01:42
试试这个。
if (ionic.Platform.isAndroid() && (imageData.indexOf("file://") === -1)) {
image.src = "file://" + imageData
} else {
image.src = imageData
}发布于 2016-11-15 14:24:20
尝试以下操作:
$cordovaCamera.getPicture(options).then(function (imageData)
{
var data = imageData;
var image = document.getElementById('myImage');
image.src = data.split('?')[0];
})https://stackoverflow.com/questions/38540611
复制相似问题