Android:SkImageDecoder :: Factory返回null从图库

时间:2015-06-05 18:55:51

标签: java android image android-intent gallery

有一天,当我试图从图库中获取图像(或动作选择意图)时,我遇到了这个问题。

原来这个问题是由于某些原因导致文件损坏引起的,因此Android会将其大小视为0,这会导致日志中出现错误,如果您尝试显示图像,则会显示为空白。 / p>

查看下面的帖子,了解我是如何解决这个问题的。

1 个答案:

答案 0 :(得分:0)

这也适用于通过其他方式检索的图像,只要您将它们视为文件或可以保持其大小。

就这样做

        File photo = new File(path_to_your_file);
        //Even if the size is 0, the file itself isn't null, so you need to check for this as well
        if(photo!=null){
            Double size = (double) photo.length();
            //transform the size from bytes to kb, for reasons.
            size = size/1024;
            //I can't recall a single instance when a file has a negative size, but lets just throw it in there to be sure.
            if(size<=0){
                Log.i("this image","ain't good");
            }else{
                 //do whatever you normally do with your file
            }
        }

快乐的编码。