【问题标题】:navigator.camera.getPicture from the gallery error "Unable to create bitmap"navigator.camera.getPicture 来自画廊错误“无法创建位图”
【发布时间】:2016-03-03 17:36:36
【问题描述】:

当我尝试从 android 的图库中获取一张图像时,出现错误“无法创建位图”。 我看过日志,发现了这个错误: /CameraLauncher(16616):文件位置是:/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20160303-WA0002.jpg W/System.err(16616): java.io.FileNotFoundException: 没有这样的文件或目录

我认为错误是由空格产生的。

我使用的是 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;

如何解决此错误?

谢谢!

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    这是一个旧帖子,但无论如何我都会回答。

    我遇到了类似的问题,但对我来说,在 GetPicture 之后尝试保存实际图像时发生了错误。正如您所怀疑的,是“WhatsApp 图像”中的空间导致了问题,所以我用“%20”替换了空间。 URI 编码可能是更好的选择。请参阅下面第 3 行的 .replace

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

    【讨论】:

      猜你喜欢
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2018-12-22
      • 2014-08-12
      相关资源
      最近更新 更多