javascript - How can I get the color from a pixel on the screen in React Native? -
i render photograph, , allow user select color touching on it. cannot find anyway retrieve painted pixels under touch event.
any help?
see example..
using ontouchlistener detect touch on imageview..
@override public boolean ontouch(view view, motionevent event) { float eventx = event.getx(); float eventy = event.gety(); float[] eventxy = new float[]{eventx, eventy}; int x = integer.valueof((int) eventxy[0]); int y = integer.valueof((int) eventxy[1]); drawable imgdrawable = ((imageview) view).getdrawable(); bitmap bitmap = ((bitmapdrawable) imgdrawable).getbitmap(); //limit x, y range within bitmap if (x < 0) { x = 0; } else if (x > bitmap.getwidth() - 1) { x = bitmap.getwidth() - 1; } if (y < 0) { y = 0; } else if (y > bitmap.getheight() - 1) { y = bitmap.getheight() - 1; } int touchedrgb = bitmap.getpixel(x, y); int r = color.red(touchedrgb); int b = color.blue(touchedrgb); int g = color.green(touchedrgb); string rr = integer.tostring(r); string bb = integer.tostring(g); string gg = integer.tostring(b); string xyz = (rr+bb+gg); colorrgb.settext("touched color: " + "#" + xyz);
here xyz rgb color code..
Comments
Post a Comment