문제

I have the x,y position on the Android emulator screen. Is there a way to find the pixel color at this specific x,y in the emulator screen?

도움이 되었습니까?

해결책

Yes you can, this is the code I use the get the RGB value of a specific pixel in any view.

view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();

int pixel = bitmap.getPixel(x,y);

int red = Color.red(pixel);
int green = Color.green(pixel);
int blue = Color.blue(pixel);

view.setDrawingCacheEnabled(false);

The int values returned are your standard 0 - 255. You can modify this code and get a color from anywhere, providing you can turn it into a bitmap. And you can use the Color API to get an actual RGB value like this:

int rgb = Color.rgb(red, blue, green);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top