I'm trying to get a Reflected Tile filter to work on iOS and I get nil back every time. Does anyone have any ideas why this would be? I can get every other CIFilter to work fine (so far). But I'm stuck on the tiles. Any idea?
func tile() -> UIImage?{
let context = CIContext(options: nil)
let tile = CIFilter.fourfoldReflectedTile()
tile.inputImage = CIImage(image: UIImage(named: "dog")!)
tile.angle = 0
tile.center = CGPoint(x: 20, y: 20)
tile.width = 20
tile.acuteAngle = 0
if let output = tile.outputImage {
if let cgimg = context.createCGImage(output, from: output.extent) {
let processedImage = UIImage(cgImage: cgimg)
return processedImage
}
}
return nil
}
This filter returns an image with infinite extent (it repeats the image in tiles). You need to crop the outputImage
to some finite extent when you want to render that into an image again:
let output = tile.outputImage?.cropped(to: <some CGRect>)