티스토리 뷰
해상도가 큰 파일을 읽어서 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;
}
}
'Programming > Android' 카테고리의 다른 글
[Android] Snackbar / SpannableString / TextInputLayout (0) | 2017.02.13 |
---|---|
[Android] Bitmap (inSampleSize) (0) | 2017.02.13 |
Mac adb 위치 (0) | 2017.01.12 |
App 내부 폴더의 파일을 외부 App에 공유하기 (FileProvider 사용) (0) | 2016.11.17 |
[Android] Internal/External storage 장단점 비교 (0) | 2016.08.12 |
댓글