Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please change decodeFile #31

Open
metacons opened this issue Feb 16, 2013 · 4 comments
Open

Please change decodeFile #31

metacons opened this issue Feb 16, 2013 · 4 comments

Comments

@metacons
Copy link

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
Copy link
Owner

thest1 commented Feb 17, 2013

Please clarify what exactly the problem is?

@metacons
Copy link
Author

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
Copy link
Owner

thest1 commented Feb 23, 2013

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

@gaddoz
Copy link

gaddoz commented Oct 6, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants