简体   繁体   中英

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. 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

I believe that the error is generated by the whitespace.

I am usign cordova cli 6.0 and this is my code:

            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. As you suspected, it's the space in "WhatsApp Images" that causes the problem, so I'm replacing the space with '%20'. URI encode might be a better option. See .replace on the 3rd line below

$cordovaCamera.getPicture(options).then(function (imageUrl) {
if (ionic.Platform.isAndroid()) {
  imageUrl = imageUrl.replace(" ", "%20");
  AppFileService.storeWallImage(imageUrl);
  resolve({
    img: imageUrl
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM