mImageVew = (ImageView) findViewById(R.id.imageView);Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.pic);//Bitmap.createScaledBitmap 以后原有的bitmap 可以recycle 了,不然会引起outofmemoryerror
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);//BitmapDrawable 创建以后如果要是用的话,构造方法里面的bitmap 千万不要recycle 如果recycle 了就会报错
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), scaledBitmap);bitmap.recycle();
//scaledBitmap.recycle();mImageVew.setImageBitmap(bitmapDrawable.getBitmap());
//scaledBitmap.recycle();
如果recycle了回报如下的错误:
2019-10-10 07:59:48.640 17460-17460/bjpkten.handler E/AndroidRuntime: FATAL EXCEPTION: mainProcess: bjpkten.handler, PID: 17460java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@70c1569at android.gra