得到的像素颜色在Android模拟器在x,y坐标 [英] get pixel color in Android emulator at x,y position

查看:816
本文介绍了得到的像素颜色在Android模拟器在x,y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有X,Android模拟器屏幕上y位置。有没有办法找到这个特定的X的像素颜色,在模拟器屏幕Y?

I have the x,y position on the Android emulator screen. Is there a way to find the pixel color at this specific x,y in the emulator screen?

推荐答案

当然可以,这是code我用得到的任何视图的特定像素的RGB值。

Yes you can, this is the code I use the get the RGB value of a specific pixel in any view.

view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();

int pixel = bitmap.getPixel(x,y);

int red = Color.red(pixel);
int green = Color.green(pixel);
int blue = Color.blue(pixel);

view.setDrawingCacheEnabled(false);

返回的整型值是标准的0 - 255您可以修改此code和从任何地方得到一种颜色,为您提供可以把它变成一个位图。你可以使用颜色API 来得到这样一个实际的RGB值

The int values returned are your standard 0 - 255. You can modify this code and get a color from anywhere, providing you can turn it into a bitmap. And you can use the Color API to get an actual RGB value like this:

int rgb = Color.rgb(red, blue, green);

这篇关于得到的像素颜色在Android模拟器在x,y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆