如何检查如果一个ImageView的背景是有一定的形象呢? [英] how can i check if an imageview background is a certain image?

查看:170
本文介绍了如何检查如果一个ImageView的背景是有一定的形象呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这样的事情到目前为止IM

so far im using something like this

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

,但它不工作

推荐答案

基本上,比较两个可绘是一种痛苦所以才将它们转换为位图,然后比较位图(更容易的解决方案),这里的code:

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
}

这篇关于如何检查如果一个ImageView的背景是有一定的形象呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆