How can I get the color of a screen pixel THROUGH ADB

superweijiafeng picture superweijiafeng · Jun 12, 2014 · Viewed 8.7k times · Source

I need to get the color information of a specific point on screen of my android phone.

Is there a way to do that through ADB?

I am now using the build-in command screencap to capture the whole screen and then read the color of the specific point. However, it is too slow.

Answer

superweijiafeng picture superweijiafeng · Jul 5, 2014

I will post an answer to my own question. The answer maybe device-specified (nexus7 2013), and you can adjust it to your own devices.

1.Firstly, I find out that the command screencap screen.png is quite slow because it take most of its time converting to png file type. So, to save time, the first step is dump screen to a raw data file. adb shell screencap screen.dump

2.Check the file size. My screen resolution is 1920*1200, and the file size is 9216012 byte. Noticing that 9216012=1920*1200*4+12, I guess the data file use 4 byte to store every pixel information, and use another 12 byte to do some mystery staff. Just do some more screencaps and I find the 12 byte at the head of each file are the same. So, the additional 12 byte is at the head of the data file.

3.Now, things are simple by using dd and hd. Assuming that I want to get the color at (x,y): let offset=1200*$y+$x+3 dd if='screen.dump' bs=4 count=1 skip=$offset 2>/dev/null | hd

I get output like 00000000: 4b 73 61 ff s 21e sum 21e The 4b 73 61 ff is my answer.