我试图在 UIImageView 上反转颜色,但问题是当我尝试反转颜色时,透明区域填充为白色:
只有白色区域应反转为黑色,但结果是:
这是我的代码:
- (void)invertColorWithImage:(UIImageView*)image {
UIGraphicsBeginImageContext(image.image.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[image.image drawInRect:CGRectMake(0, 0, image.image.size.width, image.image.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.image.size.width, image.image.size.height));
image.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
我高呼这条线以清除颜色,但没有任何改变:
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);