Как уменьшить память bitmapdrawable в Android 4.0? - PullRequest
2 голосов
/ 04 февраля 2012

У меня есть изображение, существующее в устройстве sdcard.

Путь /mnt/sdcard/001.jpg

Вот моя активность

public class BitmapMemoryTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    ImageView imv = (ImageView)findViewById(R.id.imv);
    imv.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/001.jpg"));
}
}

Вот мой макет

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imv" />

</LinearLayout>

Я тестирую этот проект на Android 3.0 и Android 4.0 и выкидываю hprof.

Объем растровой памяти в ImageView на Android 4.0 больше, чем 3,0

Android 3.0 сохраняет кучу 3,692,864 байт, Android 4.0 сохраняет кучу 7,385,320 байт

Как решить эту проблему?

PS Я не хочу снимать сэмпл изображения.

...