2017-11-15 10 views
-1

일부 장치에서는 파일에서 비트 맵 이미지를로드하려고하는데 코드가 완벽하게 작동하지만 다른 장치에서는 OutOfMemory 예외가 발생합니다.Android : 파일 객체에서 비트 맵을 가져 오는 중에 OutOfMemory 예외를 throw합니다.

String filePath = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA)); 

fileName.add(filePath); 

File file = new File(filePath); 
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
bitmapArray.add(myBitmap); 
+3

비트 맵 개체에 이미지를로드하는 동안 [이상한 메모리 부족 문제] 가능한 복제본 (https://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an- 이미지 - 비트 맵 객체) – ADM

+0

[Out of memory android issue] 중복 가능성 있음 (https://stackoverflow.com/questions/19402072/out-of-memory-android-issue) – JoxTraex

답변

0

당신은 비트 맵의 ​​크기를 알 수 있습니다 :

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inJustDecodeBounds = true; 
BitmapFactory.decodeFile(file.getAbsolutePath(), options); 
int imageHeight = options.outHeight; 
int imageWidth = options.outWidth; 

을 다음으로 설정하여 원하는 크기로 압축 sampleSize을 :

options = new BitmapFactory.Options(); 
options.inSampleSize = desired_scale_value; 
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); 

를로드하는 것을 잊지 돈`t 비 UI 스레드의 비트 맵.