标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import UIKit //--- UIImageFilterExtension.swift --- extension UIImage { //棕褐色复古滤镜(老照片效果) func sepiaTone() -> UIImage ? { let imageData = UIImagePNGRepresentation ( self ) let inputImage = CoreImage . CIImage (data: imageData!) let context = CIContext (options: nil ) let filter = CIFilter (name: "CISepiaTone" ) filter !.setValue(inputImage, forKey: kCIInputImageKey) filter !.setValue(0.8, forKey: "inputIntensity" ) if let outputImage = filter !.outputImage { let outImage = context.createCGImage(outputImage, fromRect: outputImage.extent) return UIImage ( CGImage : outImage) } return nil } } |
1
|
imageView1.image = UIImage (named: "img2.jpg" )?.sepiaTone() |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import UIKit //--- UIImageFilterExtension.swift --- extension UIImage { //黑白效果滤镜 func noir() -> UIImage ? { let imageData = UIImagePNGRepresentation ( self ) let inputImage = CoreImage . CIImage (data: imageData!) let context = CIContext (options: nil ) let filter = CIFilter (name: "CIPhotoEffectNoir" ) filter !.setValue(inputImage, forKey: kCIInputImageKey) if let outputImage = filter !.outputImage { let outImage = context.createCGImage(outputImage, fromRect: outputImage.extent) return UIImage ( CGImage : outImage) } return nil } } |
1
|
imageView1.image = UIImage (named: "img2.jpg" )?.noir() |
Swift - 给图片添加滤镜效果(棕褐色老照片滤镜,黑白滤镜)
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4858382.html