Created
August 25, 2016 01:17
-
-
Save qyzhaojinxi/2220ac3f0c433a51a0e6479b3d6136aa to your computer and use it in GitHub Desktop.
iOS改变图片颜色 #图片处理 #颜色 #iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//改变图片颜色 | |
- (UIImage *)imageWithColor:(UIColor *)color | |
{ | |
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale); | |
CGContextRefcontext = UIGraphicsGetCurrentContext(); | |
CGContextTranslateCTM(context, 0, self.size.height); | |
CGContextScaleCTM(context, 1.0, -1.0); | |
CGContextSetBlendMode(context, kCGBlendModeNormal); | |
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height); | |
CGContextClipToMask(context, rect, self.CGImage); | |
[color setFill]; | |
CGContextFillRect(context, rect); | |
UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return newImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment