从URL JSON解析大图像

时间:2015-06-24 05:19:36

标签: android json

我正在尝试解析图片...来自网址的大图片!

         // Decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f) {
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        FileInputStream stream1 = new FileInputStream(f);
        BitmapFactory.decodeStream(stream1, null, o);
        stream1.close();
        // Find the correct scale value. It should be the power of 2.
        // Recommended Size 512
        final int REQUIRED_SIZE = 70;
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE
                    || height_tmp / 2 < REQUIRED_SIZE)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        FileInputStream stream2 = new FileInputStream(f);
        Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);

        stream2.close();
        return bitmap;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

当我解析小尺寸图像时它可以正常工作,但是当我在大图像中使用它时它崩溃并且位图为空并且给我这个错误

ReadStreamToBuffer:Qmage Stream读取错误!!所需长度为12个字节,但为红色0个字节 isQmage:输入SkStreamRewindable长度小于Qmage最小大小:0

1 个答案:

答案 0 :(得分:1)