首页 > 其他 > 详细

改变图片的颜色

时间:2015-12-21 21:47:50      阅读:197      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!