0

Is there a way to get the color of the exact place on-screen using UI Automator?

Real case problem: some button changes the screen background color. I need to reach background property somehow using UI Automator. Searching in documentation and source code didn't bring any results.

Some workarounds and hacks acceptable.

AnZ
  • 1,040
  • 24
  • 54
  • Do you need the color of the background, even if there is something on top of it at those coordinates? – Ryan M Jul 02 '20 at 05:39
  • @RyanM I need to find out if there's a way to fetch color of the top-layer at a specific XY point – AnZ Jul 02 '20 at 07:06

2 Answers2

3

You can convert your view to bitmap using this Question

Then on the Bitmap call getPixel(x,y) and get the Color of the pixel on that position.

int pixel = bitmap.getPixel(100,100);
Color color = Color.valueOf(pixel);
color.alpha();
color.red();
color.green();
color.blue();
Shayan D
  • 620
  • 3
  • 14
  • Good approach, although there's a problem. I can't access View directly. Anyway, bounty is yours since no better solutions proposed. Thank you – AnZ Jul 08 '20 at 10:05
1

I saw a video of a YouTuber who used python to read RGB values from points on the screen of his monitor in real time.

https://youtu.be/aosN_FvW2e4

Python outputs values to the console though, so you can only use this to test your app on an emulator

camelCase1492
  • 642
  • 8
  • 17