gpt4 book ai didi

ios - CGContextSetFillColorWithColor 不适用于传入的颜色变量

转载 作者:行者123 更新时间:2023-11-29 04:05:50 24 4
gpt4 key购买 nike

我正在尝试使用 CGContextSetFillColorWithColor 和从 Parse 数据库中获取的颜色变量为图像着色。

以这种方式更改图像的颜色效果很好:

[...]
UIImage *image = [UIImage imageNamed:@"menuButton.png"];
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, image.CGImage);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
[...]

将 menuButton.png 更改为白色没有问题。

但是当我尝试将其更改为十六进制颜色时,我可以通过以下方式从 Parse (使用十六进制颜色实用程序)获得:

self.bgColor = [post objectForKey:@"bgColor"]; //bgColor = "#ffffff"
[...]
CGContextSetFillColorWithColor(context,
[[UIColor colorWithHexString:self.bgColor] CGColor]);

图像不再出现。这是指针问题吗?感谢您的帮助。

最佳答案

我也遇到过类似的问题,但没有找到直接的解决方案。我的解决方案是在我的 UIColor 对象上使用 -setFill 方法,而不是使用中间 CGColor 对象:

[[UIColor colorWithHexString:self.bgColor] setFill];

关于ios - CGContextSetFillColorWithColor 不适用于传入的颜色变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15251521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com