[英]navigator.camera.getPicture from the gallery error “Unable to create bitmap”
I have got the error "Unable to create bitmap" when I try to get one image from the gallery in android. 当我尝试从android的库中获取一张图像时,出现错误“无法创建位图”。 I have seen the log and I have found this error: /CameraLauncher(16616): File locaton is: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20160303-WA0002.jpg W/System.err(16616): java.io.FileNotFoundException: No such file or directory
我已经看到了日志,并且发现了以下错误:/ CameraLauncher(16616):文件位置为:/ storage / emulated / 0 / WhatsApp / Media / WhatsApp Images / IMG-20160303-WA0002.jpg W / System.err(16616) ):java.io.FileNotFoundException:没有这样的文件或目录
I believe that the error is generated by the whitespace. 我相信该错误是由空白产生的。
I am usign cordova cli 6.0 and this is my code: 我是usign cordova cli 6.0,这是我的代码:
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM,
quality: 30,
targetWidth: 300,
targetHeight: 300
};
var q = $q.defer();
navigator.camera.getPicture(function (result) {
// Do any magic you need
q.resolve(result);
}, function (err) {
q.reject(err);
}, options);
return q.promise;
How can I fix this error? 如何解决此错误?
Thank you! 谢谢!
This is an old post, but I'll answer it anyway. 这是旧帖子,但我还是会回答。
I had a similar problem, but for me the error occurred after GetPicture when trying to save the actual image. 我有一个类似的问题,但是对我来说,尝试保存实际图像时在GetPicture之后发生了错误。 As you suspected, it's the space in "WhatsApp Images" that causes the problem, so I'm replacing the space with '%20'.
正如您所怀疑的,正是导致问题的原因是“ WhatsApp Images”中的空格,因此我将其替换为“%20”。 URI encode might be a better option.
URI编码可能是一个更好的选择。 See .replace on the 3rd line below
请参阅下面第三行上的.replace
$cordovaCamera.getPicture(options).then(function (imageUrl) {
if (ionic.Platform.isAndroid()) {
imageUrl = imageUrl.replace(" ", "%20");
AppFileService.storeWallImage(imageUrl);
resolve({
img: imageUrl
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.