를로드하기위한 inSampleSize를의 최소값은 내가 큰 비트 맵을 다운 샘플링에 대한 inSampleSize
의 최소 값을 얻기 위해 다음 코드를 작성 :는 SO 검색과 답변을 많이 읽고 나면 큰 비트 맵
public Bitmap load(Context context, String image_url) throws Exception {
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image_url, bitmapOptions);
final float imageSize = (float) bitmapOptions.outWidth * (float) bitmapOptions.outHeight * 4.0f/1024.0f/1024.0f; // MB
bitmapOptions.inSampleSize = (int) Math.pow(2, Math.floor(imageSize/MemoryManagement.free(context)));
bitmapOptions.inJustDecodeBounds = false;
return BitmapProcessing.modifyOrientation(BitmapFactory.decodeFile(image_url, bitmapOptions), image_url);
}
그리고
public class MemoryManagement {
public static float free(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int memoryClass = am.getMemoryClass() - 10;
if (memoryClass < 1) memoryClass = 1;
return (float) memoryClass;
}
}
목표는 OutOfMemory 예외없이 비트 맵 샘플의 최대 크기를 얻는 것입니다. 이 코드를 신뢰할 수 있을까요?
당신이 할 일을 배우려면 나에게 설명해 줄 수 있습니까? – mmlooloo
@mmlooloo 비트 맵을로드하고 일부 효과를 적용해야합니다. 그래서 나는 OOM 예외없이 비트 맵 샘플의 최대 차원을 얻기 위해'inSampleSize'의 최소값을 찾으려고했습니다. –