简体   繁体   English

从屏幕截图中获取像素颜色

[英]Get pixel color from screenshot

I'm taking a screenshot and transform it to Bitmap我正在截屏并将其转换为 Bitmap

Bitmap bitmap = null;
while (bitmap == null) { bitmap = BitmapFactory.decodeFile(path/filename.png); }

then i want to get pixel color然后我想获得像素颜色

 int pixel = bitmap.getPixel(x, y);
 Log.i("Main", "color: " + "#" + Integer.toHexString(pixel));

and it works, but only when y<130.它有效,但仅在 y<130 时有效。 When y 140 and more i get only black color当 y 140 及以上时,我只得到黑色

2020-06-01 14:43:46.121 17451-17495/com. I/Main: color: #ff000000

screenshot resolution is 1920*1080.截图分辨率为 1920*1080。 When i try load it in ImageView all is OK当我尝试在 ImageView 中加载它时一切正常

for me works to take screenshot like this对我来说,可以像这样截取屏幕截图

Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM