Invisible SurfaceView for Camera Preview

允我心安 提交于 2019-12-29 06:54:16

问题


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: https://stackoverflow.com/a/10268650/1395697

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?

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.


回答1:


i also used the same stackOverflow answer, and get the same problem.so:

i've added this code

this.setZOrderOnTop(true);
SurfaceHolder h = this.getHolder();
h.setFormat(PixelFormat.TRANSPARENT);

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 :(




回答2:


You don't actually have to place the SurfaceView on your UI at all. We were running into the same issue and made a dummy SurfaceView. Here's our code:

SurfaceView dummy = new SurfaceView(c);
try {
    mCamera.setPreviewDisplay(dummy.getHolder());
} catch (IOException e) {

}
mCamera.setPreviewCallback(this);
mCamera.startPreview();


来源:https://stackoverflow.com/questions/10959767/invisible-surfaceview-for-camera-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!