代码之家  ›  专栏  ›  技术社区  ›  mahboudz

在两个UIView之间应用混合模式的最简单/最快方法

  •  9
  • mahboudz  · 技术社区  · 15 年前

    我正在尝试快速反转现有UIView的颜色(变成负片,如照片负片)。或者选择颜色并降低饱和度。我认为比操作位图更容易的是使用另一个全白色(或阴影)的UIView,并使用blendmodes来实现我的目标。

    有没有人用一种更简单的方法来做这件事?我希望我可以在UIView或UIImageView上设置blendmode属性,而不必子类化。。。

    基本上,如何快速反转视图,使黑色为白色,白色为黑色?

    1 回复  |  直到 15 年前
        1
  •  7
  •   mahboudz    15 年前

    这似乎是解决办法:

    板条箱UIView的一个子类。然后在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(....);
    

    我现在要去试试这个。