[Java/Android] 간단하게 사용하는 Bitmap 리사이즈(Resize) 예제

안드로이드에서 간단하게 Bitmap 이미지를 리사이즈 할 수 있는 메소드를 기억 저장용으로 기록해 둡니다. 리사이즈 하고자 하는 비트맵 이미지와 긴축 최대 길이를 지정하면 긴축에 맞추어 비율에 맞게 리사이즈를 하는 메소드입니다.

/**
 * Bitmap이미지의 가로, 세로 사이즈를 리사이징 한다.
 * 
 * @param source 원본 Bitmap 객체
 * @param maxResolution 제한 해상도
 * @return 리사이즈된 이미지 Bitmap 객체
 */
public Bitmap resizeBitmapImage(Bitmap source, int maxResolution)
{
    int width = source.getWidth();
    int height = source.getHeight();
    int newWidth = width;
    int newHeight = height;
    float rate = 0.0f;

    if(width > height)
    {
        if(maxResolution < width)
        {
            rate = maxResolution / (float) width;
            newHeight = (int) (height * rate);
            newWidth = maxResolution;
        }
    }
    else
    {
        if(maxResolution < height)
        {
            rate = maxResolution / (float) height;
            newWidth = (int) (width * rate);
            newHeight = maxResolution;
        }
    }

    return Bitmap.createScaledBitmap(source, newWidth, newHeight, true);
}