Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/hardware/camera2/DngCreator#constants) \| [Ctors](https://developer.android.com/reference/android/hardware/camera2/DngCreator#pubctors) \| [Methods](https://developer.android.com/reference/android/hardware/camera2/DngCreator#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/hardware/camera2/DngCreator#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/camera2/DngCreator#inhmethods)

# DngCreator

*** ** * ** ***


`
public

final

class
DngCreator
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/lang/AutoCloseable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.camera2.DngCreator |

<br />

*** ** * ** ***

The `https://developer.android.com/reference/android/hardware/camera2/DngCreator` class provides functions to write raw pixel data as a DNG file.


This class is designed to be used with the `https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR`
buffers available from `https://developer.android.com/reference/android/hardware/camera2/CameraDevice`, or with Bayer-type raw
pixel data that is otherwise generated by an application. The DNG metadata tags will be
generated from a `https://developer.android.com/reference/android/hardware/camera2/CaptureResult` object or set directly.


The DNG file format is a cross-platform file format that is used to store pixel data from
camera sensors with minimal pre-processing applied. DNG files allow for pixel data to be
defined in a user-defined colorspace, and have associated metadata that allow for this
pixel data to be converted to the standard CIE XYZ colorspace during post-processing.


For more information on the DNG file format and associated metadata, please refer to the
[Adobe DNG 1.4.0.0 specification](https://wwwimages2.adobe.com/content/dam/Adobe/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf).

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION` Max width or height dimension for thumbnails. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)(https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics characteristics, https://developer.android.com/reference/android/hardware/camera2/CaptureResult metadata) ` Create a new DNG object. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#close()() ` Closes this resource, relinquishing any underlying resources. |
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#setDescription(java.lang.String)(https://developer.android.com/reference/java/lang/String description) ` Set the user description string to write. |
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#setLocation(android.location.Location)(https://developer.android.com/reference/android/location/Location location) ` Set image location metadata. |
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#setOrientation(int)(int orientation) ` Set the orientation value to write. |
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#setThumbnail(android.media.Image)(https://developer.android.com/reference/android/media/Image pixels) ` Set the thumbnail image. |
| ` https://developer.android.com/reference/android/hardware/camera2/DngCreator` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#setThumbnail(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap pixels) ` Set the thumbnail image. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#writeByteBuffer(java.io.OutputStream,%20android.util.Size,%20java.nio.ByteBuffer,%20long)(https://developer.android.com/reference/java/io/OutputStream dngOutput, https://developer.android.com/reference/android/util/Size size, https://developer.android.com/reference/java/nio/ByteBuffer pixels, long offset) ` Write the `https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR` pixel data to a DNG file with the currently configured metadata. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#writeImage(java.io.OutputStream,%20android.media.Image)(https://developer.android.com/reference/java/io/OutputStream dngOutput, https://developer.android.com/reference/android/media/Image pixels) ` Write the pixel data to a DNG file with the currently configured metadata. |
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#writeInputStream(java.io.OutputStream,%20android.util.Size,%20java.io.InputStream,%20long)(https://developer.android.com/reference/java/io/OutputStream dngOutput, https://developer.android.com/reference/android/util/Size size, https://developer.android.com/reference/java/io/InputStream pixels, long offset) ` Write the `https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR` pixel data to a DNG file with the currently configured metadata. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/hardware/camera2/DngCreator#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() ` Closes this resource, relinquishing any underlying resources. | ||

## Constants

### MAX_THUMBNAIL_DIMENSION

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int MAX_THUMBNAIL_DIMENSION
```

Max width or height dimension for thumbnails.

<br />

Constant Value:

256
(0x00000100)


## Public constructors

### DngCreator

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator (CameraCharacteristics characteristics, 
                CaptureResult metadata)
```

Create a new DNG object.


It is not necessary to call any set methods to write a well-formatted DNG file.


DNG metadata tags will be generated from the corresponding parameters in the
`https://developer.android.com/reference/android/hardware/camera2/CaptureResult` object.


For best quality DNG files, it is strongly recommended that lens shading map output is
enabled if supported. See `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE`.

<br />

<br />

| Parameters ||
|---|---|
| `characteristics` | `CameraCharacteristics`: an object containing the static `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics`. This value cannot be `null`. <br /> |
| `metadata` | `CaptureResult`: a metadata object to generate tags from. This value cannot be `null`. <br /> |

## Public methods

### close

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void close ()
```

Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
`try`-with-resources statement.

<br />

### setDescription

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator setDescription (String description)
```

Set the user description string to write.


This is equivalent to setting the TIFF "ImageDescription" tag `(0x010E)`.

<br />

<br />

| Parameters ||
|---|---|
| `description` | `String`: the user description string. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/DngCreator` | this `https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)` object. This value cannot be `null`. <br /> |

### setLocation

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator setLocation (Location location)
```

Set image location metadata.


The given location object must contain at least a valid time, latitude, and longitude
(equivalent to the values returned by `https://developer.android.com/reference/android/location/Location#getTime()`,
`https://developer.android.com/reference/android/location/Location#getLatitude()`, and
`https://developer.android.com/reference/android/location/Location#getLongitude()` methods).

<br />

<br />

| Parameters ||
|---|---|
| `location` | `Location`: an `https://developer.android.com/reference/android/location/Location` object to set. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/DngCreator` | this `https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)` object. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the given location object doesn't contain enough information to set location metadata. |

### setOrientation

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator setOrientation (int orientation)
```

Set the orientation value to write.


This will be written as the TIFF "Orientation" tag `(0x0112)`.
Calling this will override any prior settings for this tag.

<br />

<br />

| Parameters ||
|---|---|
| `orientation` | `int`: the orientation value to set, one of: - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_NORMAL` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_FLIP_HORIZONTAL` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_ROTATE_180` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_FLIP_VERTICAL` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_TRANSPOSE` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_ROTATE_90` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_TRANSVERSE` - `https://developer.android.com/reference/android/media/ExifInterface#ORIENTATION_ROTATE_270` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/DngCreator` | this `https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)` object. This value cannot be `null`. <br /> |

### setThumbnail

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator setThumbnail (Image pixels)
```

Set the thumbnail image.


Pixel data is interpreted as a `https://developer.android.com/reference/android/graphics/ImageFormat#YUV_420_888` image.
Thumbnail images with a dimension larger than `https://developer.android.com/reference/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION` will be
rejected.

<br />

<br />

| Parameters ||
|---|---|
| `pixels` | `Image`: an `https://developer.android.com/reference/android/media/Image` object with the format `https://developer.android.com/reference/android/graphics/ImageFormat#YUV_420_888`. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/DngCreator` | this `https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)` object. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the given thumbnail image has a dimension larger than `https://developer.android.com/reference/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION`. |

### setThumbnail

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DngCreator setThumbnail (Bitmap pixels)
```

Set the thumbnail image.


Pixel data will be converted to a Baseline TIFF RGB image, with 8 bits per color channel.
The alpha channel will be discarded. Thumbnail images with a dimension larger than
`https://developer.android.com/reference/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION` will be rejected.

<br />

<br />

| Parameters ||
|---|---|
| `pixels` | `Bitmap`: a `https://developer.android.com/reference/android/graphics/Bitmap` of pixel data. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/DngCreator` | this `https://developer.android.com/reference/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult)` object. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the given thumbnail image has a dimension larger than `https://developer.android.com/reference/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION`. |

### writeByteBuffer

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeByteBuffer (OutputStream dngOutput, 
                Size size, 
                ByteBuffer pixels, 
                long offset)
```

Write the `https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR` pixel data to a DNG file with
the currently configured metadata.


Raw pixel data must have 16 bits per pixel, and the input must contain at least
`offset + 2 * width * height)` bytes. The width and height of
the input are taken from the width and height set in the `https://developer.android.com/reference/android/hardware/camera2/DngCreator` metadata tags,
and will typically be equal to the width and height of
`https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE`. Prior to
API level 23, this was always the same as
`https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE`.
The pixel layout in the input is determined from the reported color filter arrangement (CFA)
set in `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_COLOR_FILTER_ARRANGEMENT`. If insufficient
metadata is available to write a well-formatted DNG file, an
`https://developer.android.com/reference/java/lang/IllegalStateException` will be thrown.


Any mark or limit set on this `https://developer.android.com/reference/java/nio/ByteBuffer` is ignored, and will be cleared by this
method.

<br />

<br />

| Parameters ||
|---|---|
| `dngOutput` | `OutputStream`: an `https://developer.android.com/reference/java/io/OutputStream` to write the DNG file to. This value cannot be `null`. <br /> |
| `size` | `Size`: the `https://developer.android.com/reference/android/util/Size` of the image to write, in pixels. This value cannot be `null`. <br /> |
| `pixels` | `ByteBuffer`: an `https://developer.android.com/reference/java/nio/ByteBuffer` of pixel data to write. This value cannot be `null`. <br /> |
| `offset` | `long`: the offset of the raw image in bytes. This indicates how many bytes will be skipped in the input before any pixel data is read. Value is 0 or greater <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an error was encountered in the input or output stream. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if not enough metadata information has been set to write a well-formatted DNG file. |

### writeImage

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeImage (OutputStream dngOutput, 
                Image pixels)
```

Write the pixel data to a DNG file with the currently configured metadata.


For this method to succeed, the `https://developer.android.com/reference/android/media/Image` input must contain
`https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR` pixel data, otherwise an
`https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown.

<br />

<br />

| Parameters ||
|---|---|
| `dngOutput` | `OutputStream`: an `https://developer.android.com/reference/java/io/OutputStream` to write the DNG file to. This value cannot be `null`. <br /> |
| `pixels` | `Image`: an `https://developer.android.com/reference/android/media/Image` to write. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an error was encountered in the output stream. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if an image with an unsupported format was used. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if not enough metadata information has been set to write a well-formatted DNG file. |

### writeInputStream

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeInputStream (OutputStream dngOutput, 
                Size size, 
                InputStream pixels, 
                long offset)
```

Write the `https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR` pixel data to a DNG file with
the currently configured metadata.


Raw pixel data must have 16 bits per pixel, and the input must contain at least
`offset + 2 * width * height)` bytes. The width and height of
the input are taken from the width and height set in the `https://developer.android.com/reference/android/hardware/camera2/DngCreator` metadata tags,
and will typically be equal to the width and height of
`https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE`. Prior to
API level 23, this was always the same as
`https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE`.
The pixel layout in the input is determined from the reported color filter arrangement (CFA)
set in `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_COLOR_FILTER_ARRANGEMENT`. If insufficient
metadata is available to write a well-formatted DNG file, an
`https://developer.android.com/reference/java/lang/IllegalStateException` will be thrown.

<br />

<br />

| Parameters ||
|---|---|
| `dngOutput` | `OutputStream`: an `https://developer.android.com/reference/java/io/OutputStream` to write the DNG file to. This value cannot be `null`. <br /> |
| `size` | `Size`: the `https://developer.android.com/reference/android/util/Size` of the image to write, in pixels. This value cannot be `null`. <br /> |
| `pixels` | `InputStream`: an `https://developer.android.com/reference/java/io/InputStream` of pixel data to write. This value cannot be `null`. <br /> |
| `offset` | `long`: the offset of the raw image in bytes. This indicates how many bytes will be skipped in the input before any pixel data is read. Value is 0 or greater <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an error was encountered in the input or output stream. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the size passed in does not match the |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if not enough metadata information has been set to write a well-formatted DNG file. |

## Protected methods

### finalize

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the `finalize` method to dispose of
system resources or to perform other cleanup.


The general contract of `finalize` is that it is invoked
if and when the Java virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The `finalize` method may take any action, including
making this object available again to other threads; the usual purpose
of `finalize`, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.


The `finalize` method of class `Object` performs no
special action; it simply returns normally. Subclasses of
`Object` may override this definition.


The Java programming language does not guarantee which thread will
invoke the `finalize` method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.


After the `finalize` method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.


The `finalize` method is never invoked more than once by a Java
virtual machine for any given object.


Any exception thrown by the `finalize` method causes
the finalization of this object to be halted, but is otherwise
ignored.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |