1

So I've written some code to mask an image

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
}

The mask is just a diagonal line that half the screen is black and the other screen is white.

The desired effect is to have an image under this masked image so that half of the image is one image and the other half is another image.

What I'm seeing however is that when I return the CGImage my top layer image is showing through wherever my mask is black, but rather than be transparent when it is on the white, it is white.

How can I get the whites to be transparent? Thanks.

Unome
  • 6,750
  • 7
  • 45
  • 87
  • Possible duplicate of [iOS color to transparent in UIImage](http://stackoverflow.com/questions/8311049/ios-color-to-transparent-in-uiimage) – shallowThought Dec 14 '16 at 10:17

0 Answers0