how can i check if an imageview background is a certain image?

◇◆丶佛笑我妖孽 提交于 2019-12-11 15:48:31

问题


so far im using something like this

if (image.getDrawable() != thisContext.getResources().getDrawable(R.raw.anImage) ) {
    // do something
}

but it does not work.


回答1:


Basically, comparing two drawables is a pain so just convert them to bitmaps and then compare the bitmaps (much easier solution), here's the code:

Bitmap bitmap1 = ((BitmapDrawable)fDraw).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)sDraw).getBitmap();

if(bitmap1 == bitmap2)
{
 do some stuff
}



回答2:


try converting the Drawables to Bitmap first and then comparing:

Bitmap a = ((BitmapDrawable)d1).getBitmap();
Bitmap b = ((BitmapDrawable)d2).getBitmap();


来源:https://stackoverflow.com/questions/12207058/how-can-i-check-if-an-imageview-background-is-a-certain-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!