简体   繁体   English

Android:onPreviewFrame从未在没有SurfaceView的情况下调用

[英]Android: onPreviewFrame never called without SurfaceView

On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview. 在某些设备上,如果没有设置SurfaceView来显示摄像头预览,则不会调用onPreviewFrame However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway. 但是,我在服务中处理相机,所以我无法设置SurfaceView但我不想要有可见的预览。

How can this be done? 如何才能做到这一点? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay ? 我可以通过编程方式创建SurfaceView并使用Camera::setPreviewDisplay吗?

This must be possible or not? 这一定是否可能?

It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One... 它适用于几乎所有没有SurfaceView手机,但不适用于HTC One X和Google Nexus One ......

According to this question , creating a SurfaceView in code works fine. 根据这个问题 ,在代码中创建SurfaceView可以正常工作。 Though I don't think you can create it through a service. 虽然我认为你不能通过服务创建它。

Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. 另一种方法是在RelativeLayout创建一个1px-1px的SurfaceView并将其隐藏在其上面的其他视图中。 (visibility should still be VISIBLE ). (能见度应该仍然是VISIBLE )。 We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine. 我们将这个技巧用于Path相机UI,我们通过OpenGL渲染预览缓冲区,它工作正常。

According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. 根据配置简单的文档,可以显示可见和显示的表面视图以激活相机预览。 It may be overlayued though 但它可能会被重叠

From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. 从API 11开始,您可以使用SurfaceTexture而不是SurfaceView来从相机获取帧。 Then, instead of using Camera.setPreviewDisplay , simply use Camera.setPreviewTexture . 然后,不要使用Camera.setPreviewDisplay ,只需使用Camera.setPreviewTexture

This answer as well as this one discuss this point. 这个答案以及这一点都讨论了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM