GithubHelp home page GithubHelp logo

aaronzhou / opencamera-for-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from moo611/opencamera-for-android

0.0 1.0 0.0 7.46 MB

android 美颜相机

Java 83.03% CMake 0.43% C 1.43% GLSL 15.11%

opencamera-for-android's Introduction

OpenCamera

opencamera是一套高性能的相机框架,基于opengles+glsurfaceview,能实现实时滤镜,拍照,录制短视频,美颜磨皮等功能。

效果图

实时滤镜 生成mp4

集成

版本号

allprojects {
    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
}
dependencies 
        {
	  implementation 'com.github.moo611:OpenCamera:latestversion'
	}
//注意在android代码块里添加java8支持!!		
 	

需要添加jdk 1.8支持

compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

注意,由于demo里用的androidX,因此如果您的项目用的是v4或者v7包,会出现manifest不兼容的情况,有三种解决方案

(1)升级您的应用到androidX

(2)直接导入module的方式导入我的library

(3)用1.0.4及以下版本(不建议)

使用

添加权限

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

xml布局文件

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

开启或关闭美颜(默认开启)

 mCameraView.enableBeauty(true);

美颜程度(0~1)

mCameraView.setBeautyLevel(0.5f);

添加滤镜

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);

切换滤镜

 mCameraView.updateFilter(filters.get(pos));

切换镜头

 mCameraView.switchCamera();

拍照

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

录制视频

 private boolean isRecording = false;  // 录制状态
   ...
    
       btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                
		
		isRecording = !isRecording;
       
                mCameraView.changeRecordingState(isRecording);
		
            }
        });

       
         

设置视频保存路径及拍摄完成的回调

 
        mCameraView.setOuputMP4File(mFile);
       
        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)));

            }
        });

项目比较

多种滤镜 拍照 录制视频 是否维护
grafika X X X
gpuimage X X
magiccamera X X X
opencamera

项目借鉴了不少前辈们的作品,喜欢的麻烦点个赞,谢谢。

google/grafika

https://github.com/google/grafika

android gpuimage

https://github.com/cats-oss/android-gpuimage

magic camera

https://github.com/wuhaoyu1990/MagicCamera

opencamera-for-android's People

Contributors

moo611 avatar jindesong avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.