首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自定义相机拍照

使用自定义相机拍照
EN

Stack Overflow用户
提问于 2017-01-01 23:24:25
回答 1查看 132关注 0票数 0

我试图拍摄自定义相机视图的照片,代码没有显示任何错误,但在我的图像视图中仍然没有发生任何事情…

代码语言:javascript
复制
@IBAction func photoTake(_ sender: UIButton) {


        func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {

            if let error = error {
                print(error.localizedDescription)
            }

            if let sampleBuffer = photoSampleBuffer, let previewBuffer = previewPhotoSampleBuffer,
                let dataImage = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: sampleBuffer, previewPhotoSampleBuffer: previewBuffer) {



                let dataProvider = CGDataProvider(data: dataImage as CFData)

                let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.absoluteColorimetric)


                let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.right)





                print(UIScreen.main.bounds.width)


                self.capturedimage.image = image
                self.capturedimage.isHidden = false



            } else {

            }
        }

    }

我从这个线程Taking photo with custom camera Swift 3中获得代码

EN

回答 1

Stack Overflow用户

发布于 2017-01-12 22:22:54

代码语言:javascript
复制
if let videoConnection = stillImageOutput.connection(withMediaType:AVMediaTypeVideo){

            stillImageOutput.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (imageDataSampleBuffer, error) in

                let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
                let image = UIImage(data: imageData!)
                print("image Taked: \(image)")





            })

        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41416522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档