Heba Khater
Heba Khater

Reputation: 3

Parsing large images from url JSON

I am trying to parse images ...large images from url!

         // 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;
}

when I parse small size images it works but when I use it in large one it crashes and bitmap is null and gives me this error

ReadStreamToBuffer : Qmage Stream read error!! required length 12 bytes, but red 0 bytes isQmage : input SkStreamRewindable length is less than Qmage minimum size : 0

Upvotes: 0

Views: 789

Answers (1)

Parag Chauhan
Parag Chauhan

Reputation: 35956

Try with this library

Picasso

Volley

Android-Universal-Image-Loader

Upvotes: 1

Related Questions