Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
906 views
in Technique[技术] by (71.8m points)

android - Need to display a camera preview inside a circular view

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/>

Doing this I am getting the below result: enter image description here 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.

Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 />

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...