所以我写了一个本来应该用相机拍照的方法,然后将该照片作为UIImage
返回。但是我已经得到这个奇怪的错误Cannot convert the expression's type 'UIImage?' to type 'Void'
,我不知道什么原因引起的?下面的代码:无法转换表达式的类型'UIImage?'键入'虚空'
func captureAndGetImage()->UIImage{ dispatch_async(self.sessionQueue, {() -> Void in // Update orientation on the image output connection before capturing self.imageOutput!.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = self.previewLayer!.connection.videoOrientation if let device = self.captureDevice{ self.imageOutput!.captureStillImageAsynchronouslyFromConnection(self.imageOutput!.connectionWithMediaType(AVMediaTypeVideo), completionHandler: { (imageDataSampleBuffer, error) -> Void in if ((imageDataSampleBuffer) != nil){ var imageData:NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) var image = UIImage(data: imageData) return image } }) } }) }
我也试过return image as UIImage
,但它也不能工作。 我的猜测是,这与完成处理程序有关。
谢谢!
我看到现在的问题..在'captureStillImageAsynchronouslyFromConnection'通话,返回类型为'Void'。那么我应该如何改变它,以便它返回一个UIImage? – ddolce