如何使用swift(使用按钮切换)在GPUImage2(Switch版本)中旋转或切换前后摄像头。任何帮助都将受到高度赞赏。谢谢你。
答案 0 :(得分:1)
我找到了答案。
我再次重新加载了我的视图控制器,然后通过bool值检查它,并相应地初始化了摄像机,即渲染视图。
答案 1 :(得分:1)
让我们考虑一下GPUImage2的主要示例:
do {
camera = try Camera(sessionPreset:AVCaptureSessionPreset640x480)
filter = SaturationAdjustment()
camera --> filter --> renderView
camera.startCapture()
} catch {
fatalError("Could not initialize rendering pipeline: \(error)")
}
相机开始拍摄后,您可以通过以下方式从前向后切换:
do {
// Stop the capture of the current camera and remove its targets
sharedImageProcessingContext.runOperationSynchronously{
camera.stopCapture()
camera.removeAllTargets()
}
// Build a new Camera object, using the back or front physical camera
if camera.location == .frontFacing {
camera = try Camera(sessionPreset:.vga640x480, location:.backFacing)
} else {
camear = try Camera(sessionPreset:.vga640x480, location:.frontFacing)
}
//Rebuild the pipeline
camera --> filter --> renderView
camera.startCapture()
} catch {
print("Error switching camera : \(error)")
}
注释1: 默认的相机是后置相机,如Camera.init()的默认值所暗示:
public init(sessionPreset:AVCaptureSession.Preset,
cameraDevice:AVCaptureDevice? = nil,
location:PhysicalCameraLocation = .backFacing,
...
注释2:
Camera对象显示location
属性。不幸的是,其didSet
访问器仍在“ TODO”中:
public var location:PhysicalCameraLocation {
didSet {
// TODO: Swap the camera locations, framebuffers as needed
}
}