iOS - 检测像素的颜色? [英] iOS -- detect the color of a pixel?
问题描述
例如,假设我要检测屏幕坐标为(100,200)的像素的颜色。有没有办法做这个?
For example, suppose I want to detect the color of the pixel with screen coordinates (100, 200). Is there a way to do this?
编辑 - 我现在不担心视网膜显示问题。
EDIT -- I'm not worried about retina display issues for now.
推荐答案
这可能不是最直接的路线,但您可以:
This may not be the most direct route, but you could:
-
使用UIGraphicsBeginImageContextWithOptions抓取屏幕(请参阅Apple Q& A QA1703 - UIKit中的屏幕捕获应用)。
Then use CGImageCreateWithImageInRect to grab the portion of the resultant image you require.
最后分析一下所需的图像。结果图像。在这一点上它变得很复杂,但是幸运的是有一个现有的问题,应该告诉你的方式:
Finally analyse the resultant image. It gets complicated at this point, but thankfully there's an existing question that should show you the way: How to get the RGB values for a pixel on an image on the iphone
或者,以下博客文章附有代码:什么颜色是我的像素? iPhone上的基于图像的颜色选择器
Alternatively, there's the following blog article that has accompanying code: What Color is My Pixel? Image based color picker on iPhone
这篇关于iOS - 检测像素的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!