简体   繁体   English

如何在iOS中检测UIImage的颜色

[英]How to detect the color of an UIImage in iOS

I have a view like this : 我有这样的看法:

在此处输入图片说明

The left back button & the right button is basically two white image (set in UIButton ) with a particular opacity. 左后按钮和右按钮基本上是两个具有特定不透明度的白色图像(在UIButton设置)。 Now it's look more or less visible on this background cover photo. 现在,在此背景封面照片上或多或少可见。

But if I change the background cover photo with something else, where the opacity & color of that cover image is closer to the two button's image, then it's difficult to see those two button. 但是,如果我用其他方式更改背景封面照片,即该封面图像的不透明度和颜色更接近两个按钮的图像,那么很难看到这两个按钮。

Like this: 像这样:

在此处输入图片说明

So I just wondering, Is there any way, so that I can detect the color of my cover image and I can change those two buttons image or color according to it? 所以我只是想知道,有什么办法可以检测我的封面图像的颜色,并可以根据其更改这两个按钮的图像或颜色吗?

Any kind of reference or guidance would be very much appreciable. 任何形式的参考或指导都是非常可取的。

I think you can use this function to determinate how light/dark is the background. 我认为您可以使用此功能来确定背景的明暗程度。 Calculate an average of several pixel under your button. 计算按钮下方平均几个像素。

Have fun! 玩得开心! :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM