Skip to content

Instantly share code, notes, and snippets.

@qyzhaojinxi
Created August 25, 2016 01:17
Show Gist options
  • Save qyzhaojinxi/2220ac3f0c433a51a0e6479b3d6136aa to your computer and use it in GitHub Desktop.
Save qyzhaojinxi/2220ac3f0c433a51a0e6479b3d6136aa to your computer and use it in GitHub Desktop.
iOS改变图片颜色 #图片处理 #颜色 #iOS
//改变图片颜色
- (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