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

亡梦爱人 提交于 2019-12-03 17:18:18

问题


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?


回答1:


see here: composite colors: CALayer and blend mode on iPhone




回答2:


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";


来源:https://stackoverflow.com/questions/2939324/how-to-render-a-calayer-with-a-different-blending-mode-like-screen-or-multiply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!