原文地址: https://onevcat.com/2013/04/using-blending-in-ios/
```
+ (UIImage*)getDarkImageWithImage:(UIImage*)image {
if(![imageisKindOfClass:[UIImageclass]]) {
return nil;
}
UIGraphicsBeginImageContextWithOptions(image.size,NO, [UIScreenmainScreen].scale);
//颜色填充
[[UIColorlightGrayColor] setFill];
CGRectbounds =CGRectMake(0,0, image.size.width, image.size.height);
UIRectFill(bounds);
[image drawInRect:boundsblendMode:kCGBlendModeDestinationIn alpha:1.0f];
UIImage*highlighted =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return highlighted;
}
```
这里只简单的将图片变暗, blendMode 我只用了kCGBlendModeDestinationIn一个, 其他的没去试过, 如果需要不同的效果, 可以试试其他的mode
网友评论