我有View - “cameraView”,用于通过glView显示来自摄像机的视图。
当我设置glView = GLKView(frame: self.cameraView.bounds, context: glContext!)
时
就像它填满了整个cameraView,但ciContext?.drawImage(image, inRect:self.cameraView.bounds, fromRect:image.extent)
显示的视频帧只填充了视图的1/4(在iPhone 5c上测试过),但在iPad2上一切都很好。
glContext = EAGLContext(API: .OpenGLES2)
glView = GLKView(frame: self.cameraView.bounds, context: glContext!)
ciContext = CIContext(EAGLContext: glContext!)
self.cameraView.addSubview(glView!)
...
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!)
{
if photoTaken == false
{
let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
let image = CIImage(CVPixelBuffer: pixelBuffer)
if glContext != EAGLContext.currentContext()
{
EAGLContext.setCurrentContext(glContext)
}
glView?.bindDrawable()
ciContext?.drawImage(image, inRect:self.cameraView.bounds, fromRect:image.extent)//?
glView?.display()
}
}
感谢您的帮助!
答案 0 :(得分:1)
ciContext.drawImage(...)以像素为单位绘制图像,因此图像“inRect:”的宽度和高度必须乘以UIView.contentScaleFactor,旧版iPhone上为1.0,分辨率较高的iPhone上为2.0和3.0。