2016년 1월 21일 목요일

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



안드로이드 개발팁

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



안드로이드에서 간단하게 비트맵 이미지를 resize 할 수 있는 메소드를 기억 저장용으로 기록해둬요
resize 하려하는 Bitmap Image와 최대 길이를 지정하면 비율에 맞게 리사이즈가 돼요

아래 소스를 참고하세요~

/* 
 * 비트맵 이미지의 가로, 세로 이미지 사이즈를 리사이징 
 * @param source 원본 Bitmap 객체 
 * @param maxResolution 제한 해상도 
 * @return 리사이즈된 이미지 Bitmap 객체 
 */ 
public Bitmap resizeBitmapImg(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); 
}


have a nice day~







댓글 없음:

댓글 쓰기