需要在圆形视图内显示相机预览 [英] Need to display a camera preview inside a circular view

查看:40
本文介绍了需要在圆形视图内显示相机预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现圆形相机预览.我正在使用带有 TextureView 的 camera2 api.我添加了如下布局:

I need to implement a circular camera preview. I am using camera2 api with TextureView. I added the layout as follows:

 <FrameLayout>
 <TextureView/>
 <CircularImageView/>
 <FrameLayout/>

这样做我得到以下结果:如您所见,相机预览显示为正方形,但我希望它是圆形的,同时将黄色图像保留在背景中.我怎样才能做到这一点?我确实参考了一些关于以前提出的类似问题的示例,但它们是使用旧相机 api 而不是 TextureView 完成的.

Doing this I am getting the below result: As you can see, the camera preview is displayed in a square, but I want that to be a circular one, also keeping the yellow image in the background. How can I achieve this ? I did refer few examples on similar questions perviously asked but they are done using old camera api and not TextureView.

感谢任何帮助.

推荐答案

您需要一个常规的图像视图,而不是 CircularImageView,在其中加载具有所需大小的圆形透明孔的 png.

Instead of CircularImageView, you need a regular image view, where you load a png with circular transparent hole of desired size.

因此,建议的层次结构可能是这样的:

So, the proposed hierarchy could be something like this:

<FrameLayout size="match_parent">
   <TextureView size=<calculated_to_match_camera> centered />
   <ImageView size="match_parent" src="full-screen-gradient-with-transparent-circle-in-center.png" />
<FrameLayout />

上面的简写假定 size --> android:widthandroid:height.纹理大小以编程方式设置以适应相机预览纵横比,并通过其上方 ImageView 层中的圆孔暴露感兴趣的区域.

The shorthand above assumes size --> android:width and android:height. The texture size is set programmatically to fit the camera preview aspect ratio, and have the region of interest exposed through the circular hole in the ImageView layer above it.

这篇关于需要在圆形视图内显示相机预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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