Last active
August 29, 2015 14:02
-
-
Save akexorcist/5e87688237fd83508977 to your computer and use it in GitHub Desktop.
Resize bitmap with same ratio
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 Bitmap resizeBitmap(Bitmap bm, int maxWidth, int maxHeight) { | |
int newWidth, newHeight; | |
int bmWidth = bm.getWidth(); | |
int bmHeight = bm.getHeight(); | |
if(bmWidth > maxWidth && (maxWidth * bmHeight) / bmWidth < maxHeight) { | |
newWidth = maxWidth; | |
newHeight = (maxWidth * bmHeight) / bmWidth; | |
} else { | |
newWidth = (maxHeight * bmWidth) / bmHeight; | |
newHeight = maxHeight; | |
} | |
return Bitmap.createScaledBitmap(bm, newWidth, newHeight, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment