활동이 전체 화면으로 이미지보기를 보여주는 애플리케이션을 구현 중입니다. 이제 응용 프로그램의 파일 디렉토리에 다운로드 한 일부 이미지가 있습니다. 이미지를 이미지로 설정하여 해당 활동에서 큰 이미지를 축소하려고합니다. 내가 응용 프로그램을 사용하여 10 ~ 15 분 후 OutOfMemory 오류가 나타납니다. 오류는 BitmapFactory의 decodeFile에 있습니다. 여기 내 코드입니다 : 지금 내가 포기하고android의 이미지 축소
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height/(float)reqHeight);
} else {
inSampleSize = Math.round((float)width/(float)reqWidth);
}
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromFile(String imagePath,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(imagePath, options);
}
reqHeight = 500 reqWidth = 500
이 코드는 안드로이드 지침 페이지에 제시되어있다. 내가 빠져 나간 것이 있다면, 나를 도와주세요. 나는 많은 것을 시도했지만 어떤 해결책도 얻지 못했습니다.