Code Monkey home page Code Monkey logo

cameracompat's Introduction

CameraCompat

Create a camera preview app with beautify and camera api compatibility!

Download

screenshot

Usage

dependency

allprojects {
    repositories {
        maven {
            url  "http://dl.bintray.com/piasy/maven"
        }
    }
}

compile 'com.github.piasy:CameraCompat:1.3.0'

// sorry that it doesn't work now, pr is welcome!
compile 'com.github.piasy:BasicBeautifyProcessor:1.3.0'

initialize

// initialize in application's onCreate
CameraCompat.init(getApplicationContext());

add a ViewGroup into your layout

<FrameLayout
        android:id="@+id/mPreviewContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

start preview

// start preview in your activity or fragment
CameraCompat.Builder builder = new CameraCompat.Builder(this, this)
        .beautifyOn(false)      // default beautify option
        .flashOpen(false)       // default flash option
        .previewWidth(639)      // preview width
        .previewHeight(479)     // preview height
        .enableMirror(false)    // default mirror option
        .frontCamera(false);    // default camera option
if (mBeautifyCapable) {
    // add beautify processor, sorry that BasicBeautifyProcessor doesn't work now,
    // but in our production app, our real beautify processor works well,
    // I'm not an expert about open-gl, pr is welcome!
    builder.addProcessor(new BasicBeautifyProcessor());
}
mCameraCompat = builder.build();
mCameraCompat.startPreview(null,
        getSupportFragmentManager(),
        R.id.mPreviewContainer);    // add this ViewGroup in your layout

receive callbacks

@WorkerThread
@Override
public void onVideoSizeChanged(int width, int height) {
    Log.d("PublishActivity", "onVideoSizeChanged width = " + width
                             + ", height = " + height);
}

@WorkerThread
@Override
public void onFrameData(final byte[] data, final int width, final int height) {
    Log.d("PublishActivity", "onFrameData width = " + width
                             + ", height = " + height
                             + ", data length = " + data.length);
}

@WorkerThread
@Override
public void onError(@CameraCompat.ErrorCode int code) {
    runOnUiThread(() ->
            Toast.makeText(this, "@CameraCompat.ErrorCode " + code, Toast.LENGTH_SHORT).show());
}

control behaviour

mCameraCompat.switchBeautify();
mCameraCompat.switchCamera();
mCameraCompat.switchFlash();
mCameraCompat.switchMirror();

for resize and visibility control, just operate your ViewGroup.

Full example can be found here.

Try demo app

Demo app can be downloaded from https://fir.im/CCT . Thanks for fir.im!

Todo

  • basic beautify processor
  • configure data format received in onFrameData, currently the frame is 90 degree rotated clockwise
  • focus
  • use libyuv rather than self writen converter

cameracompat's People

Contributors

piasy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cameracompat's Issues

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.