CIFilter(iOS 13 以降)

1 min read読了の目安(約600字

iOS 13, maxOS 10.15 から CIFilter が使いやすくなった

iOS 13 以前

import CoreImage

func crystallize(image: CIImage) -> CIImage? {
    let parameters: [String: Any] = [
        kCIInputCenterKey: CIVector(cgPoint: .zero),
        kCIInputRadiusKey: 8,
        kCIInputImageKey : image
    ]
    return CIFilter(name: "CICrystallize", parameters: parameters)?.outputImage
}

iOS 13 以降

import CoreImage.CIFilterBuiltins

func crystallize(image: CIImage) -> CIImage? {
    let filter = CIFilter.crystallize()
    filter.center = .zero
    filter.radius = 8
    filter.inputImage = image
    return filter.outputImage
}