Example usage for android.hardware.camera2 DngCreator close

List of usage examples for android.hardware.camera2 DngCreator close

Introduction

In this page you can find the example usage for android.hardware.camera2 DngCreator close.

Prototype

@Override
    public void close() 

Source Link

Usage

From source file:com.almalence.opencam.SavingService.java

@TargetApi(21)
private void saveDNGPicture(int frameNum, long sessionID, OutputStream os, int width, int height,
        int orientation, boolean cameraMirrored) {
    DngCreator creator = new DngCreator(CameraController.getCameraCharacteristics(),
            PluginManager.getInstance().getFromRAWCaptureResults("captureResult" + frameNum + sessionID));
    byte[] frame = SwapHeap.SwapFromHeap(
            Integer.parseInt(getFromSharedMem("resultframe" + frameNum + Long.toString(sessionID))),
            Integer.parseInt(getFromSharedMem("resultframelen" + frameNum + Long.toString(sessionID))));

    ByteBuffer buff = ByteBuffer.allocateDirect(frame.length);
    buff.put(frame);//from  w  w w  . j  av  a2 s . c om

    int exif_orientation = ExifInterface.ORIENTATION_NORMAL;
    switch ((orientation + 360) % 360) {
    default:
    case 0:
        exif_orientation = ExifInterface.ORIENTATION_NORMAL;
        break;
    case 90:
        exif_orientation = cameraMirrored ? ExifInterface.ORIENTATION_ROTATE_270
                : ExifInterface.ORIENTATION_ROTATE_90;
        break;
    case 180:
        exif_orientation = ExifInterface.ORIENTATION_ROTATE_180;
        break;
    case 270:
        exif_orientation = cameraMirrored ? ExifInterface.ORIENTATION_ROTATE_90
                : ExifInterface.ORIENTATION_ROTATE_270;
        break;
    }

    try {
        creator.setOrientation(exif_orientation);
        creator.writeByteBuffer(os, new Size(width, height), buff, 0);
    } catch (IOException e) {
        creator.close();
        e.printStackTrace();
        Log.e("Open Camera", "saveDNGPicture error: " + e.getMessage());
    }

    creator.close();
}