【发布时间】:2013-06-11 19:05:33
【问题描述】:
我试图在 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);
【问题讨论】:
-
我希望代码没有问题,你能多解释一下......
-
我觉得图片很清晰!透明区域用白色填充,这就是问题所在,@Spynet
标签: iphone ios objective-c ipad