티스토리 뷰

해상도가 큰 파일을 읽어서 Bitmap.createBitmap을 하면 out of memory가 발생합니다.

안드로이드 약 2.8메가 이상의 힙메모리 사용시 out of memory가 발생하게 되는데요.

이미지를 메모리에 올리지 않고 그 넓이와 높이를 구하는 방법입니다.

이것으로 사이즈를 구해서 가능한 현재 화면의 해상도에 맞게 줄여서 사용하셔야 할듯 합니다.

 

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;

}

}

 

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;

}

}

 

출처: http://www.androidpub.com/31659

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함