0

メモリ使用量が少ないのはどのスタイルですか? (OOM例外を避けるため) ..

    ImageView img = (ImageView)findViewById(R.id.test) 
 // <--android:src="@drawable/test.png" declared in layout.xml

また

       res = getBaseContext().getResources();

    imgV = (ImageView)findViewById(R.id.imageView1);
    bm1 = BitmapManager.ShrinkBitmap(res , R.drawable.test, MainActivity.this);
    imgV.setImageBitmap(bm1);

    @Override
public void onDestroy() {

    if(bm1!=null)
        if(!bm1.isRecycled()){
            bm1.recycle();
            //bm1 = null;
        }
    .....
}

...


public static Bitmap ShrinkBitmap(Resources res , int id , Activity parent){
        BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
        bmpFactoryOptions.inJustDecodeBounds = true;
        bmpFactoryOptions.inPurgeable = true;
        bmpFactoryOptions.inInputShareable = true;
        bmpFactoryOptions.inPreferredConfig= Config.RGB_565;
        Bitmap bitmap = BitmapFactory.decodeResource(res, id, bmpFactoryOptions) ;          
        bmpFactoryOptions.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeResource(res, id, bmpFactoryOptions);
        return bitmap;
    }
4

1 に答える 1