【问题标题】:Capturing image that exists within video preview layer捕获存在于视频预览层中的图像
【发布时间】:2014-05-25 05:26:52
【问题描述】:

我只想捕捉视频预览层中的图像。目前,我是这样设置的:

[self setCaptureManager:[[[CaptureSessionManager alloc] init] autorelease]];
[[self captureManager] addVideoInputFrontCamera:YES]; // set to YES for Front Camera, No for Back camera
[[self captureManager] addStillImageOutput];

[[self captureManager] addVideoPreviewLayer];
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:CGRectMake(0, 0, 320, 400)];//was layerRect
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];// was CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))

[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];

就目前而言,预览层代表我想要捕捉的内容,但相机也会捕捉超出这些范围的任何内容。我无法拍照并事后裁剪,因为图像没有朝上,所以CGImageRef 不起作用。有没有办法捕捉预览层中的内容?

【问题讨论】:

    标签: ios uiimage avcapturesession avcapture


    【解决方案1】:

    这不是预览层应该做的。如果您需要拍照,您应该使用 StillImageOutput 或数据缓冲区。根据您捕获样本的方式,您应该注意相机的方向与设备方向。 jpg 图像的方向保存在名为 EXIF 的元数据字典中。
    Apple 有不同的示例code 展示了如何进行静态图像捕获。 这也是我写的一篇关于EXIF orientation的博文。

    【讨论】:

    • 对不起,如果我不清楚...我确实使用静止图像输出来捕获图像,但我已将捕获会话管理和覆盖分成两个单独的类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2013-05-09
    • 2020-04-06
    • 2021-09-27
    相关资源
    最近更新 更多