How do I make a rounded corner of a SurfaceView in android?

I am developing an Android application for streaming video. For this I am using SurfaceView. Is there a way to make the SurfaceView's corner rounded?

I tried the following code to make a rounded corner. It can make Button, Layout, TextView a rounded corner, but it doesn't work 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 SurfceView, but the view is not rounded.

How do I make a rounded corner of a SurfaceView?

Please help me on this issue.

thanks in advance

+3


source to share


2 answers


To do this, you must process each of the video frames to mask them.

Check out using lockCanvas. Basically you have to create an additional thread that blocks the canvas all the time, captures the video frame, masks it, draws and frees the canvas.



Check out this article for an example:

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

0


source


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



0


source







All Articles