Skip to content

Instantly share code, notes, and snippets.

@ksu3101
Created June 9, 2016 09:05
Show Gist options
  • Save ksu3101/d91b887ad73fc4b2445cd97bd2085dff to your computer and use it in GitHub Desktop.
Save ksu3101/d91b887ad73fc4b2445cd97bd2085dff to your computer and use it in GitHub Desktop.
resize Bitmap image
/**
* get Aspaect ratio image resize point
*
* @param src 원본 비트맵 이미지
* @param maxValue 원하는 값
* @return 리사이징된 비트맵의 width, height가 설정된 Point객체 혹은 null
*/
public static Point createScaledBitmapSize(Bitmap src, int maxValue) {
Point p = null;
if (src != null) {
if (maxValue > 0) {
int width = src.getWidth();
int newWidth = width;
int height = src.getHeight();
int newHeight = height;
float ratio = 0.0f;
if (width > height) {
if (maxValue < width) {
ratio = maxValue / (float) width;
newHeight = (int) (height * ratio);
newWidth = maxValue;
}
}
else {
if (maxValue < height) {
ratio = maxValue / (float) height;
newWidth = (int) (width * ratio);
newHeight = maxValue;
}
}
p = new Point(newWidth, newHeight);
}
}
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment