Example usage for android.hardware.camera2 DngCreator DngCreator

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

Introduction

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

Prototype

public DngCreator(@NonNull CameraCharacteristics characteristics, @NonNull CaptureResult metadata) 

Source Link

Document

Create a new DNG object.

Usage

From source file:freed.cam.apis.camera2.modules.PictureModuleApi2.java

@NonNull
private void process_rawSensor(ImageHolder image, File file) {
    Log.d(TAG, "Create DNG");

    DngCreator dngCreator = new DngCreator(cameraHolder.characteristics, image.getCaptureResult());
    //Orientation 90 is not a valid EXIF orientation value, fuck off that is valid!
    try {//  w  w w. j  a v  a 2 s .c  o m
        dngCreator.setOrientation(image.captureResult.get(CaptureResult.JPEG_ORIENTATION));
    } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
    }

    if (appSettingsManager.getApiString(AppSettingsManager.SETTING_LOCATION).equals(KEYS.ON))
        dngCreator
                .setLocation(cameraUiWrapper.getActivityInterface().getLocationHandler().getCurrentLocation());
    try {
        if (!appSettingsManager.GetWriteExternal())
            dngCreator.writeImage(new FileOutputStream(file), image.getImage());
        else {
            DocumentFile df = cameraUiWrapper.getActivityInterface().getFreeDcamDocumentFolder();
            DocumentFile wr = df.createFile("image/*", file.getName());
            dngCreator.writeImage(
                    cameraUiWrapper.getContext().getContentResolver().openOutputStream(wr.getUri()),
                    image.getImage());
        }
        cameraUiWrapper.getActivityInterface().ScanFile(file);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    image.getImage().close();
    image = null;
}

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 www.  ja  v  a 2 s. co  m*/

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