起初我以为bitmap的复制只是用“=”号做连接。。。其实大错特错
bitmapA=bitmapB 并不能把b复制给a。 而是将b的引用赋值给a。。。。因为我做了这样的试验,证明了这点。
mFilterGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
mSharedData.mFilter = position; //设置哪一个滤镜
//设置滤镜对比度 亮度 饱和度 等参数
mSharedData.mImageData=data;
// mTempBitmap=mCurrentBitmap.copy(Bitmap.Config.ARGB_8888,true);//把当前bitmap赋值给待滤镜处理的bitmap
mTempBitmap=mCurrentBitmap;
mInstaCamRS.applyFilter(mTempBitmap,mSharedData);
editImage.setImageBitmap(mCurrentBitmap);
}
});
这段代码的意思是应用滤镜在bitmap上。最后的结果是mCurrentBitmap不断被加载。。。
分析:
若mCurrentBitmap赋值给了mTempBitmap那editImage.setImageBitmap(mCurrentBitmap);应该报空。但是结果没有,因为他不是int型数据,而是一个对象,
明明处理的是mTempBitmap,但是结果却在mCurrentBitmap生效。
这就证明了,mTempBitmap=mCurrentBitmap;是把mCurrentBitmap的引用赋给了mTempBitmap,
因此对mTempBitmap进行处理,就相当于对mCurrentBitmap进行处理。
而mCurrentBitmap始终没被重新赋值,因此滤镜就叠加 了。
结果:
正确的方法应该是把注释那段代码加上,把他后面的一行去掉。在editImage.setImageBitmap(mTempBitmap);
哎,copy才是复制。才能真正将后者的rgb数组赋值给前面的bitmap。
或者用decode方法构建bitmap,那样才叫赋值
特此写一篇博客,谨记!