简体   繁体   English

画廊错误中的navigator.camera.getPicture错误“无法创建位图”

[英]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.

相关问题 Cordova navigator.camera.getPicture在Android 4.4 KitKat上以意外格式返回FILE_URI - Cordova navigator.camera.getPicture returns FILE_URI in unexpected format on Android 4.4 KitKat from gallery navigator.camera.getPicture无法正常工作 - navigator.camera.getPicture not working properly cordova navigator.camera.getPicture 在 android 中不起作用 - cordova navigator.camera.getPicture not working in android navigator.camera.getPicture在android中不起作用 - navigator.camera.getPicture not working in android 错误:使用navigator.camera.getPicture()时出现“不允许加载本地资源” - Error: “Not allowed to load local resource” when using navigator.camera.getPicture() ionic navigator.camera.getPicture不会从PHOTOLIBRARY返回图像 - ionic navigator.camera.getPicture won't return image from PHOTOLIBRARY PhoneGap navigator.camera.getPicture不触发回调 - PhoneGap navigator.camera.getPicture don't trigger Callback navigator.camera.getPicture不打开设备的默认相机应用程序 - navigator.camera.getPicture dont opens the device's default camera application navigator.camera.getPicture不会调用成功回调 - 离子框架 - cordova - navigator.camera.getPicture doesn’t call success callback - ionic framework - cordova 为什么我不能在Android应用中使用Cordova 2.7.0触发navigator.camera.getPicture? - Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM