Now basically every app needs to realize the function of beauty filter, but it is still difficult to realize it by yourself. Today I’m going to introduce you to a useful third party framework that can help us integrate quickly. opencamera for android

rendering

Integration project

allprojects {
    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
}

dependencies 
        {
	  implementation 'com. Making. Moo611: OpenCamera: 1.0.3'} // Note the addition of Java8 support!! android{ ... compileOptions {sourceCompatibility 1.8 targetCompatibility 1.8}}Copy the code

Add permissions

    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA
Copy the code

XML layout file

 <com.atech.glcamera.views.GLCameraView
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/glcamera"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
Copy the code

Add filter


private List<FilterFactory.FilterType>filters = newArrayList<>(); . filters.add(FilterFactory.FilterType.Original); filters.add(FilterFactory.FilterType.Sunrise); filters.add(FilterFactory.FilterType.Sunset); filters.add(FilterFactory.FilterType.BlackWhite); filters.add(FilterFactory.FilterType.WhiteCat); filters.add(FilterFactory.FilterType.BlackCat); filters.add(FilterFactory.FilterType.SkinWhiten);Copy the code

Switch the filter

 mCameraView.updateFilter(filters.get(pos));
Copy the code

Switch the lens

 mCameraView.switchCamera();
Copy the code

Taking pictures

 mCameraView.takePicture(new FilteredBitmapCallback() {
            @Override
            public void onData(Bitmap bitmap) {... }});Copy the code

Set output mp4 files

 mCameraView.setOuputMP4File(your file);
Copy the code

Record video

 private boolean mRecordingEnabled = false;  // Recording status. mRecordingEnabled = ! mRecordingEnabled; mCameraView.changeRecordingState(mRecordingEnabled);Copy the code

Set the mp4 record completion callback

 mCameraView.setrecordFinishedListnener(new FileCallback() {
            @Override
            public void onData(File file) {

                //update the gallery
                sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); }});Copy the code

In this way, it is easy to achieve beauty, filter and record small video functions. As for the UI interface and recording time, completely determined by their own, very convenient. If you like, I hope to give this project a thumbs-up, so that more people see.