简体   繁体   中英

How to make a rounded corner SurfaceView in android?

I am developing an android app to stream video. For this I am using SurfaceView. Is there any way to make the SurfaceView rounded corner?

I tried the following code to make the rounded corner. It can make Button, Layout, TextView rounded corner but it is not working on SurfaceView

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >


<!-- view background color -->


<!-- view border color and width -->
<stroke
    android:width="5dp"
    android:color="#FF0000" >
</stroke>

<!-- If you want to add some padding -->
<padding
    android:bottom="4dp"
    android:left="4dp"
    android:right="4dp"
    android:top="4dp" >
</padding>

<!-- Here is the corner radius -->
<corners 
    android:radius="20dp">
</corners>

This code shows a red rounded border over the SurfceView but the view is not rounded itself.

How can I make the SurfaceView rounded corner?

Please help me in this issue.

Thank in advance

In order to do this, you must process each one of the frames of the video to mask them.

Check the use of lockCanvas. Basically you must create a secondary thread that is all the time locking the canvas, taking the video frame, masking it, drawing it and releasing the canvas.

Check this article for an example:

http://androidtutorialsandtips.blogspot.com/2012/01/overriding-ondraw-method-in-surfaceview.html

You can imlement it with opengl es. There is an article( https://medium.com/@fabrantes/rounded-video-corners-on-android-3467841cc1b ) explaining how to do it and it provided source code in github. But the author use GLSurfaceView.
If you want to do it with SurfaceView . You should init opengl es context by yourself, you can refer to Grafika( https://github.com/google/grafika ) to init opengl es. Grafika us egl14 which is available since android 4.2. You can use egl10 instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM