Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akexorcist/5e87688237fd83508977 to your computer and use it in GitHub Desktop.
Save akexorcist/5e87688237fd83508977 to your computer and use it in GitHub Desktop.
Resize bitmap with same ratio
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