iOS标准相机应用程序
自定义AVFoundation录制的视频
自定义实现代码:
let chosenCameraType = AVCaptureDeviceposition.Front//get cameralet devices = AVCaptureDevice.devices()for device in devices{ if (!device.hasMediaType(AVMediaTypeVIDeo)) { continue } if (device.position != chosenCameraType) { continue } camera = (device as? AVCaptureDevice)!}do{ captureSession = AVCaptureSession() captureSession!.sessionPreset = AVCaptureSessionPresetHigh let vIDeo = try AVCaptureDeviceinput(device: camera) as AVCaptureDeviceinput captureSession!.addinput(vIDeo) let au@R_502_6901@ = try AVCaptureDeviceinput(device: AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAu@R_502_6901@)) as AVCaptureDeviceinput captureSession!.addinput(au@R_502_6901@) fileOutput = AVCaptureMovIEfileOutput() captureSession?.addOutput(fileOutput) captureSession!.startRunning() let documentsPath = NSSearchPathForDirectorIEsInDomains(.documentDirectory,.UserDomainMask,true)[0] as Nsstring let name = String(UInt64(NSDate().timeIntervalSince1970 * 1000)) fileOutput?.startRecordingToOutputfileURL(NSURL(fileURLWithPath: "\(documentsPath)/" + name + ".mov"),recordingDelegate: self)}catch let error as NSError{ print(error)}
请试试!你也会看到差异……
解决方法 我已经注意到你所描述的内容并查看了我看不到你实现的代码:backCamera.focusPointOfInterest = focusPointbackCamera.focusMode = AVCaptureFocusMode.autoFocusbackCamera.exposureMode = AVCaptureExposureMode.autoExpose
我在touchesBegan中实现了这个,这样相机就可以专注于用户触摸屏幕的区域.这是代码部分:
overrIDe func touchesBegan(_ touches: Set<UItouch>,with event: UIEvent?) { let touchPoint = touches.first let x = (touchPoint?.location(in: self.vIEw).x)! / self.vIEw.bounds.wIDth let y = (touchPoint?.location(in: self.vIEw).y)! / self.vIEw.bounds.height let realX = (touchPoint?.location(in: self.vIEw).x)! let realY = (touchPoint?.location(in: self.vIEw).y)! let focusPoint = CGPoint(x: x,y: y) let k = DrawSquare(frame: CGRect( origin: CGPoint(x: realX - 75,y: realY - 75),size: CGSize(wIDth: 150,height: 150))) if backCamera != nil { do { try backCamera.lockForConfiguration() self.prevIEwVIEw.addSubvIEw(k) } catch { print("Can't lock back camera for configuration") } if backCamera.isFocusPointOfInterestSupported { backCamera.focusPointOfInterest = focusPoint } if backCamera.isFocusModeSupported(AVCaptureDevice.FocusMode.autoFocus) { backCamera.focusMode = AVCaptureDevice.FocusMode.autoFocus } if backCamera.isExposureModeSupported(AVCaptureDevice.ExposureMode.autoExpose) { backCamera.exposureMode = AVCaptureDevice.ExposureMode.autoExpose } backCamera.unlockForConfiguration() } dispatchQueue.main.asyncAfter(deadline: .Now() + .milliseconds(500)) { k.removeFromSupervIEw() } }
当相机显示暗图像时,用户可以简单地点击屏幕,它将调整曝光和聚焦,从而使图像变亮.
总结以上是内存溢出为你收集整理的质量:自定义AVFoundation相机应用程序VS. iOS标准相机应用程序全部内容,希望文章能够帮你解决质量:自定义AVFoundation相机应用程序VS. iOS标准相机应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)