I am trying to quickly invert the colors of an existing UIView (turn into a negative, as in a photographic negative). Or to take the colors and turn down the saturation. I think easier than manipulating the bitmap is to take another UIView that is all white(or shades), and to use blendmodes to achieve my goals.
I don't see a way to direct how a UIView is drawn on top of another. Even if I subclass UIView, I don't see an easy way to drawrect using a blend more. It looks like I will have to subclass UIImageView which has a drawrect:withBlendMode.
Has anyone done this in an easier way? I was hoping I could just set a blendmode property on a UIView or UIImageView and not have to subclass...
Basically, how would you quickly invert a view so that black is white and white is black?
The Multiply mode multiplies the colors of the blending layer and the base layers, resulting in a darker color. This mode is useful for coloring shadows. The Color burn mode is named after the photography film development technique of “burning” or overexposing prints to make the colors darker.
The mix-blend-mode CSS property sets how an element's content should blend with the content of the element's parent and the element's background.
This seems to be the solution:
Crate a subclass of UIView. Then in drawRect:
[self.image drawInRect:rect];
// prepare the context to draw into
CGContextRef context = UIGraphicsGetCurrentContext();
// set the blend mode
CGContextSetBlendMode(context, kCGBlendModeDifference);
// now draw the appropriate color over the whole thing
CGContextFillRect(....);
I'm off to try this out now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With