Skip to content
This repository has been archived by the owner on Jan 19, 2020. It is now read-only.

Latest commit

 

History

History
99 lines (79 loc) · 3.07 KB

ReadMe.md

File metadata and controls

99 lines (79 loc) · 3.07 KB

NDK Camera

Build Status Build Status

Simplified Android Camera 2 API.
Available for both Java/JNI.

  • API level: 24+
  • NDK

Reference

How to

Build

For Windows environment, latest Android Studio is recommended.
For Linux/MacOS, Gradle 5.3 will be enough.

$ git clone https://github.com/luncliff/NdkCamera
$ cd ./NdkCamera
$ gradle clean assemble # Build: libndk_camera.so & NdkCamera.aar

Test

Connect your device and run the test with Gradle. Please reference the test codes.

$ gradle connectedAndroidTest   # Run test

Use

The following code shows working with SurfaceView class.

package dev.example;

// ...
import dev.ndcam.*;

// Expect we already have a camera permission
public class SurfaceDisplay
    implements  SurfaceHolder.Callback
{
    SurfaceView surfaceView;
    Surface surface;
    ndcam.Device camera;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // ...

        // Load/Init library
        ndcam.CameraModel.Init();

        surfaceView = findViewById(R.id.surfaceView);
        SurfaceHolder holder = surfaceView.getHolder();
        holder.setFixedSize(1920, 1080);
        holder.setFormat(ImageFormat.YUV_420_888);
        holder.addCallback(this);
    }
    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        // Get all devices in array form
        for(ndcam.Device device : ndcam.CameraModel.GetDevices())
            if(device.facing() == CameraCharacteristics.LENS_FACING_BACK)
                camera = device;
    }
    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder,
                               int format, int width, int height) {
        // Make a repeating caputre request with surface
        surface = surfaceHolder.getSurface();
        camera.repeat(surface);
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
        // No more capture
        if(camera != null)
            camera.stopRepeat();
    }
}