I'm trying to apply this mask to the original image
Notice there are some grey areas, I want to keep everything except PURE black.
I've found this code
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
)
return (UIImage(cgImage: (imageReference.masking(imageMask!))!))
}
But it does the opposite, it removes all white pixels instead.
Edit ---
For example if the above mask is implied to a pure color background
right now so far the solution submitted gives this image
Notice there are holes in the middle, grey areas. Everything should be solid blue. In order words, the mask should only take out PURE black areas.