thest1 / LazyList

Lazy load of images in Android
http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012
MIT License
1.2k stars 497 forks source link

Please change decodeFile #31

Open metacons opened 11 years ago

metacons commented 11 years ago

If I use your code quality of image corrupted . private Bitmap decodeFile(File f) { final int MAX_SIZE = 400; try {

        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > MAX_SIZE || o.outWidth > MAX_SIZE) {
            scale = (int) Math.pow(
                    2,
                    (int) Math.round(Math.log(MAX_SIZE / (double) Math.max(
                            o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(f);
        Bitmap b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
        return b;

    } catch (IOException e) {

    } catch (OutOfMemoryError e) {
        this.clearCache();
    }

    return null;
}
thest1 commented 11 years ago

Please clarify what exactly the problem is?

metacons commented 11 years ago

Dear Fedov,

First of all thank you for your sharing this project I test your code Galaxy note series and got "out of memory exception". Changed it above code and it was solved. But I double checked your code and I guess that did not same as I used previous. Maybe It was my mistake. Had you change already?

thest1 commented 11 years ago

Not sure what exactly are you talking about? What line of code?

gaddoz commented 9 years ago

plus for metacons. the quality of images are really improved with your code!