如何设置摄像头视图为背景,享有呢?视图、摄像头、如何设置、背景

2023-09-06 11:37:33 作者:今天小编

所以,我想使背景到我的应用程序之一看看未来主义。我想到了一个主意,使画面看起来几乎是透明的还可以欣赏到它的。因此,这将是这个样子:

So, I'm trying to make the background to one of my apps look "futuristic." I thought of an idea to make the screen look almost transparent yet have views over it. So, it would look something like this:

我想,我可以用相机捕捉到手机的背景(没有拍照,只是有在后台实时视图),然后,如果可能的话,放置一个半透明轻微模糊的ImageView在这一点。最后,最重要的是我可以将包括ImageButtons其他视图。

I'm thinking that I can use the camera to capture the background of the phone (without taking a picture, just having the real time view in the background) and then, if possible, place a semi-transparent slightly blurred ImageView over that. Finally, on top of that I can place the other views including the ImageButtons.

所以,我的问题是,我将如何去这样做?我已搜查,但没有发现任何有关。它必须是可能的;它只是怎么办呢?我不指望你给我所有的code作为一个答案,只是如果你有什么想法,可以帮助或链接,或code,可以点我在正确的方向,这将是极大的$ AP p $ pciated!谢谢!

So, my question is how would I go about doing this? I have searched but haven't found anything relevant. It must be possible; its just how to do it? I don't expect you to give me all the code as an answer, just if you have any ideas that can help or links or code that can point me in the right direction, it would be greatly appreciated! Thanks!

推荐答案

应该不会太难上手。有位于这里样本,告诉你如何打开摄像头并绘制preVIEW到SurfaceView。既然要叠加在相机preVIEW顶你的其他意见,只是请确保您使用的相机preVIEW的SurfaceView包含在的FrameLayout(文档位于的这里)。该的FrameLayout可以让你插入孩子的看法和他们的z索引使用它们插入的顺序。因此,如果您插入SurfaceView然后插入某种这将是一个按钮z有序的SurfaceView的前面,你可以设置它的alpha值,以便它可以或多或少透明。所有这一切说,你会做你想要怎样的立场,即在相机preVIEW前面渲染,因为在不同屏幕尺寸使用的FrameLayout可能会以不同定位查看你的观点一些试验和错误。另外,我想从分层在彼此顶部太多意见望而却步,因为合成器将不得不弄清楚如何这一切渲染成可能会影响性能的单一窗口。

It shouldn't be too hard to get started. There are samples located here that show you how to open the camera and draw the preview onto a SurfaceView. Since you want to overlay your other Views on top of the camera preview, just make sure that the SurfaceView that you are using for the camera preview is contained inside a FrameLayout (docs located here). The FrameLayout lets you insert child views and they are z-indexed using the order they are inserted. Therefore, if you insert your SurfaceView and then insert a Button of some kind it will be z-ordered in front of the SurfaceView and you can set its alpha value so that it can be more or less transparent. All that said, you will have to do some trial and error for how you want to position your views that are being rendered in front of the camera preview because a FrameLayout used on different screen sizes might position the Views differently. Also, I'd stay away from layering too many Views on top of one another because the compositor will have to figure out how to render all of it into a single window which could impact performance.