基于背景图像的文本颜色 [英] Text color based on background image

查看:75
本文介绍了基于背景图像的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图有一个带有文本标签叠加的背景图片
基于背景图像确定文本颜色的最佳/好动态方法是什么,因此它可以读取(目前我只对确定感兴趣如果文字颜色应该是暗的还是浅的)

My view has a background image with a text label overlay What's the best/good dynamic way to determine text color based on the background image so it can be readable (For now, I'm only interested on determining if text color should be dark or light)

谢谢:)

推荐答案

使用提到的链接找到平均颜色

Find the average color with the link woz mentioned

然后设置文字样式

CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
[averageColor getRed:&red green:&green blue:&blue alpha:&alpha];

int threshold = 105;
int bgDelta = ((red * 0.299) + (green * 0.587) + (blue * 0.114));

UIColor *textColor = (255 - bgDelta < threshold) ? [UIColor blackColor] : [UIColor whiteColor];

这样的事情。

你可以也可以使用上面的链接从图像中获取 UIColor 并使用亚光的类别,让UIColor变浅或变暗。

You could also use the link above to get the UIColor from the image and use matt's category for UIColor to get light or dark.

这篇关于基于背景图像的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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