簡體   English   中英

從屏幕截圖中獲取像素顏色

[英]Get pixel color from screenshot

我正在截屏並將其轉換為 Bitmap

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

然后我想獲得像素顏色

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

它有效,但僅在 y<130 時有效。 當 y 140 及以上時,我只得到黑色

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

截圖分辨率為 1920*1080。 當我嘗試在 ImageView 中加載它時一切正常

對我來說,可以像這樣截取屏幕截圖

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