android bitmap回收,Android中Bitmap回收问题

使用Bitmap的静态方法createScaledBitmap来创建一个符合规格的Bitmap的时候,原生的bitmap是否需要回收?

代码如下:

private void initDragBitmap() {

Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mingren);

mDragBitmap = Bitmap.createScaledBitmap(srcBitmap, FLOAT_BALL_WIDTH, FLOAT_BALL_HEIGHT, true);

srcBitmap.recycle();

}

代码中srcBitmap是否需要回收?

补充问题:

看了大家的回复,基本可以确定如果srcBitmap后续不再使用了,确实是可以手动recycle的,同时它本身也是个局部变量,是可以等待系统GC的。

那新问题来了(或者说我最初想问的问题来了),当createScaledBitmap方法中传入的宽和高跟srcBitmap相同时,通过createScaledBitmap代码注释可以看出它是将srcBitmap返回了,这个时候我强行recycle了srcBitmap,会不会导致mDragBitmap也为null?

源码注释:

/**

* Creates a new bitmap, scaled from an existing bitmap, when possible. If the

* specified width and height are the same as the current width and height of

* the source bitmap, the source bitmap is returned and no new bitmap is

* created.

*

* @param src The source bitmap.

* @param dstWidth The new bitmap's desired width.

* @param dstHeight The new bitmap's desired height.

* @param filter true if the source should be filtered.

* @return The new scaled bitmap or the source bitmap if no scaling is required.

* @throws IllegalArgumentException if width is <= 0, or height is <= 0

*/

public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight,

boolean filter) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值