             }
             // draw effect image
             context.saveGState()
-            if let maskCGImage = mask?.cgImage {
+            if let maskCGImage = mask?._makeCgImage() {
                 context.clip(to: outputRectInPoints, mask: maskCGImage)
             }
             if let _cgImage = effectCGImage?.takeUnretainedValue() {

        let rect = CGRect(origin: .zero, size: scaledSize)
        UIGraphicsBeginImageContextWithOptions(rect.size, false, scale)
        defer { UIGraphicsEndImageContext() }
        guard let cgImage = self.cgImage, let context = UIGraphicsGetCurrentContext() else { return nil }
        context.clip(to: rect)
        if horizontally {
            context.rotate(by: CGFloat.pi)

    /// - Returns: The color of the image at the specific point or pixel.
    public func color(at point: CGPoint, scale: CGFloat) -> UIColor! {
        let rect = CGRect(origin: .zero, size: size)
        guard let cgImage = self._makeCgImage(), rect.contains(point) else { return nil }
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let bytesPerPixel = pow(scale, 2.0)
        let bytesPerRow   = Int(bytesPerPixel) * cgImage.width
