Last active
February 24, 2016 01:42
-
-
Save luanvuhlu/c1a5d8b6dd22460a98ef to your computer and use it in GitHub Desktop.
Scale bitmap image Android
This file contains hidden or 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 Bitmap scaleBitmapDown(Bitmap bitmap, int maxDimension) { | |
int originalWidth = bitmap.getWidth(); | |
int originalHeight = bitmap.getHeight(); | |
int resizedWidth = maxDimension; | |
int resizedHeight = maxDimension; | |
if (originalHeight > originalWidth) { | |
resizedHeight = maxDimension; | |
resizedWidth = (int) (resizedHeight * (float) originalWidth / (float) originalHeight); | |
} else if (originalWidth > originalHeight) { | |
resizedWidth = maxDimension; | |
resizedHeight = (int) (resizedWidth * (float) originalHeight / (float) originalWidth); | |
} else if (originalHeight == originalWidth) { | |
resizedHeight = maxDimension; | |
resizedWidth = maxDimension; | |
} | |
return Bitmap.createScaledBitmap(bitmap, resizedWidth, resizedHeight, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment