Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render a CALayer with a different blending mode, like screen or multiply?

I have a UIImageView and want it to be displayed with a specific blend mode. I know the iPhone has different blend modes, and it's probably possible to do it with a lot of CG code… but maybe there's a nice way with the CALayer of UIImageView?

like image 819
dontWatchMyProfile Avatar asked May 30 '10 15:05

dontWatchMyProfile


People also ask

How do I change my screen from blending mode?

Modify a layer's blend modeIn the HUD, click the Blend Mode pop-up menu, then choose a different mode. In the Properties Inspector, click the Blend Mode pop-up menu, then choose a different mode. Choose Object > Blend Mode, then choose a different mode from the submenu.

What are 3 different blending modes?

Some of the more commonly used blend modes are Multiply, Screen, Overlay and Soft Light.


1 Answers

Set the compositingFilter of a view's layer to a supported blend mode string. From the docs, a layer's compositingFilter is

A CoreImage filter used to composite the layer and the content behind it.

To obtain a list of Core Image filters, print out the filter names defined by a kCICategoryCompositeOperation

[CIFilter filterNamesInCategory:kCICategoryCompositeOperation]

or directly as

[CIFilter filterNamesInCategory:@"CICategoryCompositeOperation"]

The array will include Core Image filters in the form

{
   CIColorBlendMode,
   CIColorBurnBlendMode,
   CIColorDodgeBlendMode,
   CIMultiplyBlendMode,
   ...
}

To use the CIMultiplyBlendMode, set "multiplyBlendMode" as the compositingFilter on the layer

self.layer.compositingFilter = @"multiplyBlendMode";
like image 106
bdev Avatar answered Sep 23 '22 23:09

bdev