如何更改图像tintColor [英] How can I change image tintColor

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

问题描述

我从服务器接收图像,然后根据用户选择的颜色,图像颜色将会改变。

I'm receiving image from a server, then based on a color chosen by the user, the image color will be changed.

我尝试了以下内容:

_sketchImageView.image = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[_sketchImageView setTintColor:color];

我的目标与我的目标相反(UIImage外面的白色用所选颜色着色)。

i got the opposite of my goal (the white color outside UIImage is colored with the chosen color).

出了什么问题?

我需要在这个问题上做同样的事情,所提供的解决方案并没有解决我的情况。
如何在iOS中更改图像tintColor和WatchKit

i need to do the same in this question,the provided solution doesn't solve my case. How can I change image tintColor in iOS and WatchKit

推荐答案

尝试为自己生成新图像

UIImage *newImage = [_sketchImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIGraphicsBeginImageContextWithOptions(image.size, NO, newImage.scale);
[yourTintColor set];
[newImage drawInRect:CGRectMake(0, 0, image.size.width, newImage.size.height)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

_sketchImageView.image = newImage;

并使用它。

祝你好运

=======更新=======

此解决方案将更改所有像素图像的颜色。

This solution will only change color of all pixel's image.

示例:我们有一个图书图片: http://pngimg.com/upload/book_PNG2113.png

Example: we have a book image: http://pngimg.com/upload/book_PNG2113.png

运行上面的代码后(exp: TintColor 是RED)。我们有:

And after running above code (exp: TintColor is RED). We have:

SO:图片的设置取决于您的设计方式

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

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