哪种风格消耗更少的内存?(避免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;
}