我有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()
    }
}


感谢帮助!

最佳答案

ciContext.drawImage(...)以像素为单位绘制图像,因此图像“ inRect:”的宽度和高度必须乘以UIView.contentScaleFactor,在旧iPhone上为1.0,在较高分辨率的iPhone上为2.0和3.0。

关于ios - 视频帧仅占 View 的1/4-GL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33112273/

10-09 17:59