问题描述
我需要获取相机预览数据,但不可见预览。
因为我在服务中做所有这些,我不得不创建一个虚拟的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.
我使用的代码此答案:
I've used the code from this answer:http://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.
任何其他方式来做到这一点?
Do you know any other way to do this?
我现在做的只是使一个可见的 SurfaceView
的宽度和高度1,然后使用特定颜色创建 ImageView
覆盖,以便您不会看到 SurfaceView $ c $的颜色变化c>。但是这不是很整齐,我真的想做得更好。
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答案,并得到相同的problem.so:
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方法,而不是活动(或在我的情况下的服务),并得到它trasparent,但日志抱怨放弃的帧:(
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用于相机预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!