如何在UIImage中屏蔽XOR

时间:2017-02-20 11:29:43

标签: ios swift3 uiimageview image-masking

我希望UIImage屏蔽这样的内容,如下图所示,但使用coregraphics masking,任何答案都表示赞赏enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个

func maskImage(image:UIImage, mask:(UIImage))->UIImage{

        let imageReference = image.cgImage
        let maskReference = mask.cgImage

        let imageMask = CGImage(maskWidth: maskReference!.width,
                                height: maskReference!.height,
                                bitsPerComponent: maskReference!.bitsPerComponent,
                                bitsPerPixel: maskReference!.bitsPerPixel,
                                bytesPerRow: maskReference!.bytesPerRow,
                                provider: maskReference!.dataProvider!, decode: nil, shouldInterpolate: true)

        let maskedReference = imageReference!.masking(imageMask!)

        let maskedImage = UIImage(cgImage:maskedReference!)

        return maskedImage
    }