如何使用surfaceview在android中将框架的外部部分设置为背景 [英] How to set background to the outer portion of frame in android using surfaceview

查看:278
本文介绍了如何使用surfaceview在android中将框架的外部部分设置为背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何填充框架的外部部分。我需要在框架内显示相机时刻。其余部分将填充我们选择填写的颜色。

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.

请建议我应该做什么?

您的真实指导和支持将会是额外的,您的努力将非常感谢您一旦确定完成此操作。

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

推荐答案

如果您不想要相机,您有两个选项预览以填充SurfaceView覆盖的整个区域:

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


  1. 在SurfaceView之上绘制一些东西。

  2. 使用OpenGL ES以任何您想要的形状呈现相机预览。

选项#1非常简单。 SurfaceView表面在View UI层下方合成,所以在View中绘制的任何内容都会显示在顶部(例如,包含的图像中的蓝色圆圈)。只需在不想要相机预览出现的地方画不透明像素。您应该可以通过指定自定义 onDraw()来使用SurfaceView的视图。

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.

这篇关于如何使用surfaceview在android中将框架的外部部分设置为背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆