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

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

问题描述

我需要实现圆形摄像机预览.我正在将camera2 api与TextureView一起使用.我添加了如下布局:

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:width android: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天全站免登陆