Now basically every app needs to realize beauty filter function, and if they go to realize, there are still some difficulties. Today we show you a useful third-party framework, it can help us to quickly integrate. opencamera for android
Renderings
Integrated Project
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
dependencies
{
implementation 'com.github.moo611:OpenCamera:1.0.3'
}
//注意添加java8支持!!!
android{
...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
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
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" />
Add Filters
private List<FilterFactory.FilterType>filters = new ArrayList<>();
...
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);
Filter switch
mCameraView.updateFilter(filters.get(pos));
Cutaways
mCameraView.switchCamera();
Photograph
mCameraView.takePicture(new FilteredBitmapCallback() {
@Override
public void onData(Bitmap bitmap) {
...
}
});
Set the output mp4 file
mCameraView.setOuputMP4File(your file);
Record video
private boolean mRecordingEnabled = false; // 录制状态
...
mRecordingEnabled = !mRecordingEnabled;
mCameraView.changeRecordingState(mRecordingEnabled);
Setting mp4 recording completion callback
mCameraView.setrecordFinishedListnener(new FileCallback() {
@Override
public void onData(File file) {
//update the gallery
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.fromFile(file)));
}
});
In this way, it is easy to realize the beauty, and the filter function to record small video. As for their own UI interface and recording time, entirely by himself to be, very convenient. If you like, I want to give this project a point like this, so that more people see it.