본문 바로가기

개발/Android 개발 주저리

[Android] OutOfMemory Error 해결방법 , 이미지 처리

이미지를 메모리에 올리지 않고, 이미지의 사이즈 구하는 방법

 ( 이는 OutOfMemory 오류를 방지합니다 )

/** Get Bitmap's Width **/
 public static int getBitmapOfWidth( String fileName ){
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);
        return options.outWidth;
    } catch(Exception e) {
    return 0;
    }
 }
 
 /** Get Bitmap's height **/
 public static int getBitmapOfHeight( String fileName ){
 
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);
 
        return options.outHeight;
    } catch(Exception e) {
        return 0;
   }
 }