Skip to content

Please change decodeFile  #31

Description

@metacons

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions