Last active
February 28, 2022 00:28
-
-
Save ThomazPom/d5a6d74acdec5889fabcb0effe67a160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
How to use it boss
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
Get color at X;Y pos for any android device in shell without root