美文网首页
拍照相片处理GPUImageStillCamera

拍照相片处理GPUImageStillCamera

作者: br_MorningStar | 来源:发表于2017-12-01 11:42 被阅读42次

步骤: 创建相机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
        }
    }
}

相关文章

网友评论

      本文标题:拍照相片处理GPUImageStillCamera

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