如何设置背景框在Android中使用surfaceview外侧部如何设置、背景、surfaceview、Android

2023-09-07 01:07:33 作者:我再强大你也是我的软肋

好家伙,

我的问题是我怎么能填满整个画面的外侧部分。我需要只显示框架内的摄像头时刻。的部分的其余部分将充满了我们选择填写的颜色

My problem is how can I fill the outer portion of the frame. I need to show the camera moments inside the frame only. The rest of the portion will filled up with the color what we choose to fill.

下面这个是整个背景从相机拍摄的,但我不希望这样。

Here this is the whole background captured from the camera but I don't want this.

请给我建议,我应该怎么办?

Please suggest me what I should do?

您真正的指导和支持将是额外的,你的努力将是非常美联社preciated一旦你确定使用此完成。

Your true guidance and support will be additional and your efforts will highly be appreciated once you're sure to done with this.

推荐答案

您有两种选择,如果你不希望摄像头preVIEW来填补SurfaceView覆盖的整个区域:

You have two options if you don't want the camera preview to fill the entire area covered by the SurfaceView:

绘制的SurfaceView之上的东西。使用的OpenGL ES呈现在你想要的任何形状的摄像头preVIEW。

选项#1 pretty简单。该SurfaceView表面复合视图UI层以下,所以任何你画一个视图将出现在顶部(如您包含在图像中的蓝色圆圈)。只画不透明像素无处不在,你不希望相机preVIEW出现。您应该能够通过自定义使用SurfaceView的视图的onDraw()

Option #1 is pretty straightforward. The SurfaceView surface is composited below the View UI layer, so anything you draw in a View will appear on top (e.g. the blue circle in the image you included). Just draw opaque pixels everywhere you don't want the camera preview to appear. You should be able to use the SurfaceView's View by specifying a custom onDraw().

选项#2是更复杂,但确实给你如何显示摄像机图像更大的灵活性。在 Grafika 中的从相机质感的活动说明了这一点。

Option #2 is more involved, but does give you more flexibility in how you display the camera image. The "texture from camera" activity in Grafika demonstrates this.