Answers for "cifilter image preserve orientation"

0

cifilter image preserve orientation

var filterNames: [String] = ["CIPhotoEffectTonal","CIPhotoEffectNoir","CIMaximumComponent","CIMinimumComponent","CIDotScreen", "CISepiaTone", "CIFalseColor", "CIColorInvert", "CIColorPosterize", "CIPhotoEffectChrome", "CIPhotoEffectInstant"]

    let CIfilterName = filterNames[indexPath.row]
    print(CIfilterName)

    let ciContext = CIContext(options: nil)
    let startImage = CIImage(image: originalImage)

    let filter = CIFilter(name: CIfilterName)
    filter!.setDefaults()

    filter!.setValue(startImage, forKey: kCIInputImageKey)
    let filteredImageData = filter!.valueForKey(kCIOutputImageKey) as! CIImage
    let filteredImageRef = ciContext.createCGImage(filteredImageData, fromRect: filteredImageData.extent)

    let originalOrientation: UIImageOrientation = (imageView.image?.imageOrientation)!
    let originalScale: CGFloat = (imageView.image?.scale)!
    let newPtImage: UIImage = UIImage.imageWithCGImage(filteredImageRef, scale: originalScale, orientation: originalOrientation)
    imageView.image = newPtImage

    imageView.image = UIImage(CGImage: filteredImageRef);
Posted by: Guest on February-23-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language