步骤: 创建相机GPUImageStillCamera --> 设置相机横竖屏 --> 创建滤镜 --> 设置滤镜 --> 创建预览画面GPUImageView --> 捕捉画面
拍照 捕获照片作为图像处理(camera!.capturePhotoAsImageProcessedUp)
import UIKit
import GPUImage
class ViewController: UIViewController {
@IBOutlet var imageView : UIImageView!
fileprivate lazy var camera : GPUImageStillCamera? = GPUImageStillCamera(sessionPreset: AVCaptureSession.Preset.high.rawValue, cameraPosition: .back)
fileprivate lazy var filter : GPUImageBrightnessFilter = GPUImageBrightnessFilter()
override func viewDidLoad() {
super.viewDidLoad()
//竖屏
camera!.outputImageOrientation = .portrait
//创建滤镜(美白 曝光 )
// let filter = GPUImageBrightnessFilter()
filter.brightness = 0.7
camera!.addTarget(filter) //添加滤镜
//创建GUPImageView 显示实时画面
let showView = GPUImageView(frame: view.bounds)
view.insertSubview(showView, at: 0)
filter.addTarget(showView)
//捕捉画面
camera!.startCapture()
}
@IBAction func takePhoto(){
camera!.capturePhotoAsImageProcessedUp(toFilter: filter) { (image, error) in
//后面参数有是否保存成功 参数 可一监听
UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
self.imageView.image = image
self.camera!.stopCapture()
self.camera = nil
}
}
}
网友评论