码迷,mamicode.com
首页 > 其他好文 > 详细

改变图片的颜色

时间:2015-12-21 21:47:51      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

定义
#import <UIKit/UIKit.h>

@interface UIImage (ChangeImageColor)
/**
 *  改变图片的颜色
 *
 *  @param tintColor <#tintColor description#>
 *
 *  @return <#return value description#>
 */
- (UIImage *) imageWithTintColor:(UIColor *)tintColor;

@end

实现
- (UIImage *)imageWithTintColor:(UIColor *)tintColor{

    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
    [tintColor setFill];

    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);

    UIRectFill(bounds);

    //Draw the tinted image in context
    [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];

    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return tintedImage;
}

 

改变图片的颜色

标签:

原文地址:http://www.cnblogs.com/TheYouth/p/5064888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!