用于相机预览的不可见 SurfaceView [英] Invisible SurfaceView for Camera Preview
问题描述
我只需要获取相机预览数据,而不是可见预览.由于我在服务中完成所有这些操作,因此我必须创建一个虚拟的 SurfaceView,它的效果非常好.
I need to get camera preview data only, but not visible preview. Since I'm doing all this in a service, I had to create a dummy SurfaceView, which works very well.
我使用了这个答案中的代码:https://stackoverflow.com/a/10268650/1395697
I've used the code from this answer: https://stackoverflow.com/a/10268650/1395697
但是,使用 TYPE_SYSTEM_OVERLAY
它不起作用.它是不可见的,但没有收到预览数据(在 onPreviewFrame()
中).当我将此参数更改为 0 时,我会获得预览数据,但 SurfaceView
是可见的.
However, with TYPE_SYSTEM_OVERLAY
it didn't work. It was invisible but no preview data was received (in onPreviewFrame()
). When I change this argument to 0, I get preview data, but the SurfaceView
is visible.
你知道其他方法吗?
我现在所做的只是制作一个可见的 SurfaceView
,宽度和高度为 1,然后我创建一个具有特定颜色的 ImageView
叠加层,这样您就不会查看 SurfaceView
的颜色变化.但这一点都不整洁,我真的很想做得更好.
What I did now is just make a visible SurfaceView
with width and height of 1 and then I create an ImageView
overlay with a specific color so that you don't see the change of color of the SurfaceView
. But this isn't neat at all and I'd really like to do it a bit better.
推荐答案
我也用了同样的stackOverflow答案,得到同样的问题.所以:
i also used the same stackOverflow answer, and get the same problem.so:
我已添加此代码
this.setZOrderOnTop(true);
SurfaceHolder h = this.getHolder();
h.setFormat(PixelFormat.TRANSPARENT);
到我的 surfaceChanged 方法,而不是活动(或我的情况下的服务),并让它变得透明,但日志抱怨废弃的帧:(
to my surfaceChanged method, instead of the activity (or a service at my case), and got it trasparent, but the Log complains on abandoned frames :(
这篇关于用于相机预览的不可见 SurfaceView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!