0

I'm creating an app that takes pictures in .dng format in order to process them. I'm using the camera2 API. I was able to take pictures and save them into my smartphone Android 13, but in .jpg format. But when I change my code in order to save them with .dng extension, I get an error.

The part of my code that takes and saves the picture is as follows:

Size largest = choosePictureSize(map.getOutputSizes(ImageFormat.RAW_SENSOR));
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
ImageFormat.RAW_SENSOR, /*maxImages*/1);
mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
private String getPictureFilePath(Context context) {
        final File dir = context.getExternalFilesDir(null);
        return (dir == null ? "" : (dir.getAbsolutePath() + "/"))
                + System.currentTimeMillis() + ".dng";
    }

Listener:

case ImageFormat.RAW_SENSOR: {
                    DngCreator dngCreator = new DngCreator(mCameraCharacteristics, mCaptureResult);
                    FileOutputStream output = null;
                    try {
                        output = new FileOutputStream(mFile);
                        dngCreator.writeImage(output, mImage);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        mImage.close();
                        if (null != output) {
                            try {
                                output.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    break;
                }
@Override
        public void onCaptureProgressed(@NonNull CameraCaptureSession session,
                                        @NonNull CaptureRequest request,
                                        @NonNull CaptureResult partialResult) {
            process(partialResult);
        }

        @Override
        public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                       @NonNull CaptureRequest request,
                                       @NonNull TotalCaptureResult result) {
            process(result);
        }

I'm having this error:

java.lang.IllegalArgumentException: Null argument to DngCreator constructor
Marinette
  • 1
  • 1

1 Answers1

0

Based on the error message, either mCameraCharacteristics or mCaptureResult is null. Maybe you're clearing one of them before your callback has a chance to run?

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47