Iphone 反转UIImageView上的颜色
我尝试反转UIImageView上的颜色,但问题是当我尝试反转颜色时,透明区域会填充白色: 只有白色区域应反转为黑色,但结果是: 这是我的密码:Iphone 反转UIImageView上的颜色,iphone,ios,objective-c,ipad,Iphone,Ios,Objective C,Ipad,我尝试反转UIImageView上的颜色,但问题是当我尝试反转颜色时,透明区域会填充白色: 只有白色区域应反转为黑色,但结果是: 这是我的密码: - (void)invertColorWithImage:(UIImageView*)image { UIGraphicsBeginImageContext(image.image.size); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCo
- (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);
从阅读代码来看,这似乎是罪魁祸首
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.image.size.width, image.image.size.height));
您将填充颜色设置为白色,然后在下一行说填充整个图像
我还没有机会运行代码,但这看起来很可能我发现这个方法很有效:
我希望代码没有问题,你可以再解释一下……我认为图片很清楚!透明区域填充白色,这就是问题所在,@Spynet