AVCaptureVideoPreviewLayer:拍摄快照 [英] AVCaptureVideoPreviewLayer: taking a snapshot

查看:143
本文介绍了AVCaptureVideoPreviewLayer:拍摄快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图模拟默认相机应用程序中显示的动画,其中相机取景器的快照将动画到应用程序显示的角落。



保存解决这个问题的关键的AVCaptureVideoPreviewLayer对象不是非常开放这些要求:试图创建一个新的层的副本与..

   - (id)initWithLayer:(id)layer 

一个空的图层,没有图像快照,所以显然有一些更深的魔法在这里。



你的线索/ boos是最受欢迎的。

$ b $



以下是可能的解决方案,没有太大的IMO:




  • AVCaptureStillImageOutput AVCaptureVideoDataOutput 添加到 AVCaptureSession 。当您将 sessionPreset 设置为 AVCaptureSessionPresetHigh 时,您将开始通过API获取帧,当您切换到 AVCaptureSessionPresetPhoto 时,可以拍摄实际图像。所以在拍摄照片之前,你可以切换到视频,获取一帧,然后返回相机。重要的警告是,相机在摄像机和图片相机之间切换需要长时间(几秒钟)。


  • 只使用相机输出( AVCaptureStillImageOutput ),并使用 UIGetScreenImage 获取手机的屏幕捕获。然后,您可以裁剪控件,只留下图像。如果你在图像上显示UI控件,这会变得很复杂。此外,根据帖子,苹果开始拒绝应用程式


  • 除了这些,我也尝试过使用 AVCaptureVideoPreviewLayer 。有信息可保存UIView或CALayer到UIImage。但它都产生清晰或白色的图像。我尝试访问图层,视图层,上层 presentationLayer modelLayer ,但无效。我猜, AVCaptureVideoPreviewLayer 中的数据是非常内部的,而不是真正的正常层基础设施的一部分。




希望这有助于,
Oded。


I'm trying to emulate the animation seen in the default camera app, where a snapshot of the cameras viewfinder is animated into the corner of the apps display.

The AVCaptureVideoPreviewLayer object that holds the key to solving this problem isn't very open to these requirements: trying to create a copy of it in a new layer with ..

- (id)initWithLayer:(id)layer

.. returns an empty layer, without the image snapshot, so clearly there is some deeper magic going on here.

Your clues/boos are most welcome.

M.

解决方案

facing the same woes, from a slightly different angle.

Here are possible solutions, that none are too great IMO:

  • You can add to an AVCaptureSession both an AVCaptureStillImageOutput and an AVCaptureVideoDataOutput. When you set the sessionPreset to AVCaptureSessionPresetHigh you'll start getting frames by the API, and when you switch to AVCaptureSessionPresetPhoto you can take real images. So right before taking the picture, you can switch to video, get a frame, and then return to camera. Major caveat is that it takes a "long" time (couple of seconds) for the camera to switch between the video camera and picture camera.

  • Another option would be to use only the camera output (AVCaptureStillImageOutput), and use UIGetScreenImage to get a screen capture of the phone. You could then crop out the controls and leave only the image. This gets complicated if you're showing UI controls over the image. Also, according to this post, Apple started rejecting apps that use this function (it was always iffy).

  • Aside from these I also tried playing with AVCaptureVideoPreviewLayer. There's this post to save a UIView or CALayer to a UIImage. But it all produces clear or white images. I tried accessing the layer, the view's layer, the superlayer, the presentationLayer, the modelLayer, but to no avail. I guess the data in AVCaptureVideoPreviewLayer is very internal, and not really part of the regular layer infrastructure.

Hope this helps, Oded.

这篇关于AVCaptureVideoPreviewLayer:拍摄快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆