Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #cifilter #image #preserve #orientation
ADD COMMENT
Topic
Name
4+3 =