디스크에 1280x1280 JPG가 있는데 ImageView에 표시 할 이미지의 영역을 디코딩 할 때 (측면이 잘리는) 다음 코드를 사용하고 있습니다. 이미지에서 위쪽과 아래쪽을 잘라내는 것과 비슷한 문제가 있습니다. 에이서 ICONIA A100 (4.0.3) 코드가 완벽하게 작동 및 힙에는 메모리를 할당하지 제공된 경우 재순환 비트 맵으로 지역 디코딩에 왜 BitmapRegionDecoder가 많은 양의 메모리를 할당합니까?
private Bitmap decodeBitmapRegion(InputStream in, Rect region, Bitmap recycleBitmap) {
LOGD(TAG, "decodeBitmapRegion region=" + region + ", recycleBitmap=" + recycleBitmap);
Bitmap bitmap = null;
BitmapRegionDecoder decoder = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inBitmap = recycleBitmap;
try {
decoder = BitmapRegionDecoder.newInstance(in, false);
bitmap = decoder.decodeRegion(region, options);
} catch (IllegalArgumentException e){
LOGE(TAG, "Failed to recycle bitmap for rect=" + region, e);
} catch (IOException e) {
LOGE(TAG, "Failed to decode into rect=" + region, e);
} finally {
if (decoder != null) decoder.recycle();
}
return bitmap;
}
. logcat에는 GC가 없거나 힙 메시지가 증가합니다. 또한 4.2.0을 실행하는 Nexus 7에서도 올바르게 작동합니다.
Motorola Xoom (4.0.4)에서이 코드는 다음 logcat을 생성합니다. 첫번째 dalvikvm-heap grow (4738256 바이트)은 아마도 BitmapRegionDecoder의 데이터 용이고 두 번째 (3603216 바이트)는 이미지를 저장하는 데 필요한 메모리 양 (800x1126x4)과 일치합니다. 스키 아 오류가 있습니다.
8522 LocationImageLoader D decodeBitmapRegion region=Rect(240, 77 - 1040, 1203), [email protected]
8522 dalvikvm D GC_FOR_ALLOC freed 8213K, 28% free 22782K/31623K, paused 34ms
8522 dalvikvm-heap I Grow heap (frag case) to 26.808MB for 4738256-byte allocation
8522 dalvikvm D GC_CONCURRENT freed 6K, 14% free 27403K/31623K, paused 3ms+7ms
8522 skia D WARNING: One-shot allocator has already allocated (alloc count = 1)
8522 dalvikvm D GC_FOR_ALLOC freed 0K, 14% free 27403K/31623K, paused 33ms
8522 dalvikvm-heap I Grow heap (frag case) to 30.238MB for 3603216-byte allocation
8522 dalvikvm D GC_FOR_ALLOC freed 0K, 3% free 30922K/31623K, paused 41ms
설정 options.inPreferredConfig = Bitmap.Config.RGB_565; 비트 맵이 올바르게 재활용 된 것처럼 Xoom의 두 번째 할당을 무효화하는 것으로 보이지만 여전히 디코더에 할당 된 메모리가 있습니다.
전체 이미지 (1280x1280) 및 BitmapFactory를 사용한 재활용 작업은 영역에서 요구하는 것보다 전체 이미지를 저장하는 데 훨씬 많은 메모리가 사용되지만 작동합니다.
왜 Xoom이 작동하지 않지만 Acer은 모두 Android 4.0.x를 실행 중일 때 이해할 수 없습니다.
Xoom이 GPU에서 디코 딘/자르기/인코딩을 수행하지 않는 것 같습니다. – auval
@uval hardwareAccelerated가 true로 설정되어 있지만 불행히도 GPU에서 수행되지 않는 작업에 대한 이론은 의미가 있지만 차이는 없습니다. –