0
私はtakePhotoボタンで写真をキャプチャすることができますが、AVCapturePhotoOutputにメンバー 'captureStillImageAsynchronously'がないと言ってtakePhotoにエラーがあります。AVCapturePhotoOutputにメンバー 'captureStillImageAsynchronously'がありません
のViewControllerは
import UIKit
import AVFoundation
import CoreImage
@available(iOS 10.0, *)
class ViewController: UIViewController {
var captureSession = AVCaptureSession()
var sessionOutput = AVCapturePhotoOutput()
var previewLayer = AVCaptureVideoPreviewLayer()
@IBOutlet weak var imageViewReal: UIImageView!
@IBOutlet weak var cameraView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let deviceSession = AVCaptureDeviceDiscoverySession.init(deviceTypes: [.builtInDuoCamera, .builtInTelephotoCamera, .builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: .unspecified)
for device in (deviceSession?.devices)! {
if (device as AnyObject).position == AVCaptureDevicePosition.front {
do {
let input = try AVCaptureDeviceInput(device: device)
if captureSession.canAddInput(input) {
captureSession.addInput(input)
if captureSession.canAddOutput(sessionOutput){
captureSession.addOutput(sessionOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.connection.videoOrientation = .portrait
cameraView.layer.addSublayer(previewLayer)
cameraView.addSubview(takePhoto)
previewLayer.position = CGPoint (x: self.imageViewReal.frame.width/2, y: self.imageViewReal.frame.height/2)
previewLayer.bounds = imageViewReal.frame
captureSession.startRunning()
}
}
}
catch {
print("Error")
}
}
}
}
@IBAction func takePhoto(_ sender: Any) {
if let videoConnection = sessionOutput.connection(withMediaType: AVMediaTypeVideo) {
sessionOutput.captureStillImageAsynchronously(from: videoConnection, completionHandler: {
buffer, Error in
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer)
UIImageWriteToSavedPhotosAlbum(UIImage(data : imageData!)!, nil, nil, nil)
})
}
}
}
あなたの努力のために余裕を持っていますが、私もline#54の 'cameraView.addSubview(takePhoto)' errorr: 'Any型の値をUIviewに変換できません。 –
あなたの努力のためにDrawinをやっていますが、 54行目のエラーです。cameraView.addSubview(takePhoto)errorr:Any型の値をUIviewに変換できません –