当一个imageview 使用了 setimagebitmap(bit); 之后 如何从imageview中获取到bit

来源:互联网 发布:linux中echo e 编辑:程序博客网 时间:2024/06/08 08:56
下面是SDK里面Imageview.setImageBitmap()的源码,他根本没有保存bitmap的引用,而只是将bitmap包装成了一个BitmapDrawable再setImageDrawable(),如果你非得获得bitmap的引用的话,继承ImageView,在他里面添加一个bitmap的成员变量,然后重写setImageBitmap方法,每次调这个方法的时候就将bitmap的引用保存住,然后提供一个getBitmap()方法返回bitmap的引用。但是我感觉这样做没撒意义,如果你是为了更快的回收内存的话,如果bitmap还在显示你就调用bitmap.recycle()方法的话会报错,希望对你有帮助。
/**
* Sets a Bitmap as the content of this ImageView.

* @param bm The bitmap to set
*/
@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) {
// if this is used frequently, may handle bitmaps explicitly
// to reduce the intermediate drawable object
setImageDrawable(new BitmapDrawable(mContext.getResources(), bm));
}
0 0
原创粉丝点击