Created
November 30, 2012 09:21
-
-
Save atermenji/4174718 to your computer and use it in GitHub Desktop.
BitmapFactory.Options inSampleSize calculating
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 static int calculateInSampleSizeInside(BitmapFactory.Options options, int maxWidth, int maxHeight) { | |
final int height = options.outHeight; | |
final int width = options.outWidth; | |
int inSampleSize = 1; | |
if (height > maxHeight || width > maxWidth) { | |
if (width > height) { | |
inSampleSize = Math.round((float) height / (float) maxHeight); | |
} else { | |
inSampleSize = Math.round((float) width / (float) maxWidth); | |
} | |
if (height < maxHeight && width > maxWidth) { | |
inSampleSize = Math.round((float) width / (float) maxWidth); | |
} | |
if (height > maxHeight && width < maxWidth) { | |
inSampleSize = Math.round((float) height / (float) maxHeight); | |
} | |
if (inSampleSize == 1) { | |
inSampleSize += 1; | |
} | |
} | |
return inSampleSize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works better: