有没有一种方法可以直接访问Android中显示器像素的颜色? [英] Is there a way to directly access the color of a pixel of the display in Android?

查看:98
本文介绍了有没有一种方法可以直接访问Android中显示器像素的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否知道在应用程序执行过程中是否有某种方式可以获取所有像素(或一个像素,无所谓)的颜色信息? 我需要获取特定时刻整个显示器的平均颜色的东西. 我只找到了使用屏幕截图的解决方案,但是这需要花费一些时间进行计算. 实际上,即使有,我也会做类似的事情:

Do you know if there is a way to get, at some point during the execution of an application, an information of the colors of all the pixels (or one pixel, it's indifferent)? The thing I need to get the average color of the entire display at a particular instant. I only found solutions that use screenshots of the display, but this thing takes time for the computation. Practically, even if there is, I would do something like:

Display display = ((WindowManager)getSystemService(this.WINDOW_SERVICE)).getDefaultDisplay();
int pixel = display.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);

推荐答案

您可以将根视图作为位图获取,然后对像素进行采样.

You can get your root view as a bitmap and then sample pixels.

例如:

View myLayout = findViewById(R.id.myRootLayout);
myLayout.setDrawingCacheEnabled(true);
Bitmap bitmap = myLayout.getDrawingCache();
myLayout.setDrawingCacheEnabled(false);

//sample a pixel
int color = bitmap.getPixel(20,20);

这篇关于有没有一种方法可以直接访问Android中显示器像素的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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