UIColor colorWithPatternImage 改变图像的颜色 [英] UIColor colorWithPatternImage changes the color of the image

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

问题描述

我有以下代码.

//Create a view to place repeated arrow in.
UIView *rootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];

//Add Repeated Arrows to the top of the view using a color pattern.
UIImage *arrowImage = [UIImage imageNamed:@"arrow-down"];
UIColor *repeatedArrowColor = [UIColor colorWithPatternImage:arrowImage];
CGRect repeatedArrowFrame = CGRectMake(0, 0, 320.0, [arrowImage size].height);
UIView *repeatedArrowView = [[UIView alloc] initWithFrame:repeatedArrowFrame];
[repeatedArrowView setBackgroundColor:repeatedArrowColor];

[rootView addSubview:repeatedArrowView];

所使用的图像是带有彩色箭头的 png #323232.我通过右键单击 .app 文件并选择显示包内容"来验证这一点.

The image being used is a png with arrows colored #323232. I verified this by right clicking the .app file and selecting Show Package Contents.

然而,当图案出现在 iOS 模拟器屏幕上时,箭头的颜色是 #262626 或 #252525.

However when the pattern appears on the iOS simulator screen the color of the arrows are #262626 or #252525.

有人遇到过这个问题吗?如果是这样,您是如何解决的,或者您是否解决了这个问题?

Has anyone run into this problem? If so, how did you fix, or did you work-around it?

推荐答案

总之每个人都有这些问题.如果您在预览中打开该图像并使用 pixie(开发工具),您肯定会看到与文件中不同的像素值.该值与您在模拟器中看到的值不同吗?

In short everyone has these problems. If you open that image in Preview and use pixie (dev tool), you will see a different value for the pixels than is in the file for sure. Is that value different from what you see in the Simulator?

您的 png 中是否嵌入了颜色配置文件?如果您删除它,它可能会有所帮助(pngcrush 将这样做作为一种选择).如果没有,或者没有修复它,那么您可能需要首先使用以下方法将图像加载为 CGImageRef:

Do your png's have a color profile embedded in them? It may help if there is one if you delete it (pngcrush will do this as an option). If there is none, or that does not fix it, then you may need to load your image first as a CGImageRef using:

CGImageRef CGImageCreateWithPNGDataProvider (
   CGDataProviderRef source,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);

并使用颜色意图(第一个)和解码数组作为最后一个选项.

and fool around with the color intent (first) and as a last option the decode array.

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

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