Android - Get Color From ImageView with ColorFIlter Applied to Drawable -


i'm trying color of imageview within gridview i've applied color filter previously. i'm running on nexus 4 4.2.2

i'm altering color of imageview this. actual color of image white before apply filter.

drawable myicon = getresources().getdrawable(r.drawable.bufferbuildercolor3);                        myicon.setcolorfilter(new porterduffcolorfilter(color.rgb(color.red(color),color.green(color), color.blue(color)),porterduff.mode.multiply)); 

now doesn't alter source images color want. remains white.

my problem i'm trying reference color after i've lost data used set it. want long press on imageview , color.

i found code @ below question, doesn't appear work returns white (255,255,255), color of original image, not filter. how pixel colour in android?

imageview imageview = ((imageview)v); bitmap bitmap = ((bitmapdrawable)imageview.getdrawable()).getbitmap(); int pixel = bitmap.getpixel(x,y);  int redvalue = color.red(pixel); int bluevalue = color.blue(pixel); int greenvalue = color.green(pixel); 

i've tried stuff below, crashes when call getcolorfilter.

imageview image = (imageview)findviewbyid(r.drawable.bufferbuildercolor3); colorfilter test = image.getcolorfilter(); 

i'm not sure else do, except maybe find x/y of actual grid position, , screens background color @ point rather images. seems there should easier way though?

you tag imageview (or view matter) data you're interested in retrieving later on. example, tag view same color use construct porterduffcolorfilter:

color tagcolor = color.rgb(color.red(color),color.green(color), color.blue(color)); // tag imageview.settag(tagcolor);  // tag tagcolor = (color) imageview.gettag(); 

obviously tag garbage collected when related view does.

alternatively, approach in 3rd code snippet might work if fix up. you're trying inflate view looking drawable id - doesn't make sense. id should in form of r.id.imageview_id, i.e.:

imageview image = (imageview) findviewbyid(r.id.imageview); colorfilter test = image.getcolorfilter(); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -