iOS——检测像素的颜色? [英] iOS -- detect the color of a pixel?

查看:30
本文介绍了iOS——检测像素的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,假设我想用屏幕坐标 (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:

  1. 使用 UIGraphicsBeginImageContextWithOptions 来抓取屏幕(参见 Apple Q&A QA1703 - "UIKit 应用程序中的屏幕截图").

然后使用 CGImageCreateWithImageInRect 获取所需的结果图像部分.

Then use CGImageCreateWithImageInRect to grab the portion of the resultant image you require.

最后分析得到的图像.在这一点上它变得复杂,但幸运的是,有一个现有的问题应该为您指明方向:如何获取 iphone 图像上像素的 RGB 值

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

或者,有以下带有代码的博客文章:What Color is My像素?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屋!

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