I am trying to invert colors on UIImageView, but the problem is when I try to invert colors , the transparent area fills with white color :
only white areas should be inverted to black color , but the result is :
here is my codes :
- (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();
}
I chante this line to clear color but nothing changed :
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);