图库中存在8000X8000的图片导致应用直接退出

来源:互联网 发布:淘宝组装机 知乎 编辑:程序博客网 时间:2024/04/30 10:18

在MediaProvider中过滤这张图片

 if ((initialValues != null) && (match == IMAGES_MEDIA)) {
            String path = initialValues.getAsString(MediaStore.MediaColumns.DATA);
            if(path != null)
            {
                MediaFile.MediaFileType mediaFileType = MediaFile.getFileType(path);
                int fileType = (mediaFileType == null ? 0 : mediaFileType.fileType);
                if (MediaFile.isImageFileType(fileType)) {
                    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
                    bitmapOptions.inSampleSize = 1;
                    bitmapOptions.inJustDecodeBounds = true;
                    bitmapOptions.outWidth = 0;
                    bitmapOptions.outHeight = 0;
                    BitmapFactory.decodeFile(path, bitmapOptions);
                    long px = bitmapOptions.outWidth * bitmapOptions.outHeight;
                    if(px > 4092 * 4092) {
                        //unsupport image is not inserted
                        Log.e(TAG, "find huge/unsupport image, path = " + path + ", mWidth = " + bitmapOptions.outWidth + ", mHeight = " + bitmapOptions.outHeight);
                        return null;
                    }
                }
            }
        }

0 0
原创粉丝点击