Last active
June 8, 2016 09:43
-
-
Save josemigallas/bb657860e72a3f4a26302e8ccdcfde2e to your computer and use it in GitHub Desktop.
Class for decoding a bitmap from a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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