import UIKit
import GPUImage
class ViewController: UIViewController {
fileprivate var camera : GPUImageStillCamera!
fileprivate var filter : GPUImageBrightnessFilter!
var isFirst : Bool = true
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func startCapturing() {
if isFirst {
// 1.创建GPUImage中的相机 100 : 1
let camera = GPUImageStillCamera(sessionPreset: AVCaptureSessionPresetHigh, cameraPosition: .front)
camera?.outputImageOrientation = .portrait
self.camera = camera
// 2.添加滤镜
let filter = GPUImageBrightnessFilter()
camera?.addTarget(filter)
self.filter = filter
// 3.创建GPUImageView对象
let gpuImageView = GPUImageView(frame: view.bounds)
view.insertSubview(gpuImageView, at: 0)
filter.addTarget(gpuImageView)
isFirst = false
}
// 4.开始采集
camera?.startCapture()
}
@IBAction func stopCapturing() {
camera.stopCapture()
}
@IBAction func rotateCamera() {
camera.rotateCamera()
}
@IBAction func takePhoto() {
camera.capturePhotoAsImageProcessedUp(toFilter: filter) { (image : UIImage?, error : Error?) in
UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
}
}
}