美文网首页
Swift图片滤镜效果

Swift图片滤镜效果

作者: 旧雨伞时 | 来源:发表于2016-08-17 11:04 被阅读0次

    这只是在初涉swift中的一小块. 在此做个小笔记.

    import UIKit
    
    class ViewController: UIViewController {
    
        @IBOutlet weak var photoImageView: UIImageView!
        
        // Create a place to render the filtered image
        let context = CIContext(options: nil)
        
        @IBAction func applyFilter(sender: AnyObject) {
            
            // Create an image to filter
            let inputImage = CIImage(image: photoImageView.image)
         
            // Create a random color to pass to a filter
            let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]
            
            // Apply a filter to the image
            let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)
            
            // Render the filtered image
            let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())
            
            // Reflect the change back in the interface
            photoImageView.image = UIImage(CGImage: renderedImage)
        
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    }
    

    相关文章

      网友评论

          本文标题:Swift图片滤镜效果

          本文链接:https://www.haomeiwen.com/subject/pqsmsttx.html