Skip to content

Instantly share code, notes, and snippets.

@ThomazPom
Last active February 28, 2022 00:28
Show Gist options
  • Save ThomazPom/d5a6d74acdec5889fabcb0effe67a160 to your computer and use it in GitHub Desktop.
Save ThomazPom/d5a6d74acdec5889fabcb0effe67a160 to your computer and use it in GitHub Desktop.
widthheight=$(wm size | sed "s/.* //")
width=$(($(echo $widthheight | sed "s/x.*//g" )+0))
height=$(($(echo $widthheight | sed "s/.*x//g" )+0))
GetColorAtPixel () {
x=$1;y=$2;
rm ./screen.dump 2> /dev/null
screencap screen.dump
screenshot_size=$(($(wc -c < ./screen.dump)+0));
buffer_size=$(($screenshot_size/($width*height)))
let offset=$width*$y+$x+3
color=$(dd if="screen.dump" bs=$buffer_size count=1 skip=$offset 2>/dev/null | hd | grep -Eo "([0-9A-F]{2} )" |sed "s/[^0-9A-F]*\$//g" | sed ':a;N;$!ba;s/\n//g' |cut -c3-8)
echo $color;
}
GetColorAtPixel2 () {
x=$1;y=$2;
rm ./screen.dump 2> /dev/null
screencap screen.dump
screenshot_size=$(($(wc -c < ./screen.dump)+0));
buffer_size=$(($screenshot_size/($width*height)))
let offset=$width*$y+$x+3
color=$(dd if="screen.dump" bs=$buffer_size count=1 skip=$offset 2>/dev/null | /system/xbin/hd | awk '{ print toupper($0) }' | grep -Eo "([0-9A-F]{2})+" | sed ':a;N;$!ba;s/\n//g' | cut -c9-14 )
echo $color;
}
@ThomazPom
Copy link
Author

ThomazPom commented Mar 24, 2021

@amrashraf1992

Download the file on your android device
source with a dot ( . ) the file from a terminal view an example

. ./Android_GetColorAtPixel.sh 

Call function GetColorAtPixel with desired $x and $y pixels view an example
Example :

GetColorAtPixel 0 100

Color of pixel will be shown
You may want to store result in a variable

color_of_pixel=$(GetColorAtPixel 0 100)
echo color is $color_of_pixel

If function GetColorAtPixel does not work, try GetColorAtPixel2

color_of_pixel=$(GetColorAtPixel2 0 100)
echo color is $color_of_pixel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment