I use this function to detect if UIImage has transparency:
extension UIImage {
public func isTransparent() -> Bool {
guard let alpha: CGImageAlphaInfo = self.cgImage?.alphaInfo else { return false }
return alpha == .first || alpha == .last || alpha == .premultipliedFirst || alpha == .premultipliedLast
}
}
But it doesn't work. I tried it with a png Image with no transparency but it still return true.
Loop for each pixel is not a good idea because it's too expensive i guess. Any idea how to check if UIImage has transparency, like this image: image
