Skip to content

Instantly share code, notes, and snippets.

@josemigallas
Last active June 8, 2016 09:43
Show Gist options
  • Save josemigallas/bb657860e72a3f4a26302e8ccdcfde2e to your computer and use it in GitHub Desktop.
Save josemigallas/bb657860e72a3f4a26302e8ccdcfde2e to your computer and use it in GitHub Desktop.
Class for decoding a bitmap from a file
public class ReducedBitmapFactory {
public static final int MAX_IMAGE_WIDTH = 1200;
public static final int MAX_IMAGE_HEIGHT = 1200;
public static Bitmap decodeFile(String photoPath) {
BitmapFactory.Options bmOptions = new android.graphics.BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, bmOptions);
int photoHeight = bmOptions.outHeight;
int photoWidth = bmOptions.outWidth;
int scaleFactor = Math.min(
photoWidth / MAX_IMAGE_WIDTH,
photoHeight / MAX_IMAGE_HEIGHT
);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
return BitmapFactory.decodeFile(photoPath, bmOptions);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment