# DngCreator

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

# DngCreator

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/hardware/camera2/DngCreator "View this page in Java")  

```
class DngCreator : AutoCloseable
```

|---|----------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                             ||
| ↳ | [android.hardware.camera2.DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) |

The[DngCreator](https://developer.android.com/reference/kotlin/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[android.graphics.ImageFormat#RAW_SENSOR](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int)buffers available from[android.hardware.camera2.CameraDevice](https://developer.android.com/reference/kotlin/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[android.hardware.camera2.CaptureResult](https://developer.android.com/reference/kotlin/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).

## Summary

|                                                                                                                                    Constants                                                                                                                                     ||
|----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [MAX_THUMBNAIL_DIMENSION](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION:kotlin.Int) Max width or height dimension for thumbnails. |

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

|                                                                                                                                                                                                                                                                                                                                                                                                                                                               Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                ||
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                      | [close](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#close())`()` <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | [setDescription](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#setDescription(kotlin.String))`(`description:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Set the user description string to write.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | [setLocation](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#setLocation(android.location.Location))`(`location:` `[Location](https://developer.android.com/reference/kotlin/android/location/Location.html#)`)` Set image location metadata.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | [setOrientation](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#setOrientation(kotlin.Int))`(`orientation:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Set the orientation value to write.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | [setThumbnail](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#setThumbnail(android.graphics.Bitmap))`(`pixels:` `[Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#)`)` Set the thumbnail image.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | [setThumbnail](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#setThumbnail(android.media.Image))`(`pixels:` `[Image](https://developer.android.com/reference/kotlin/android/media/Image.html#)`)` Set the thumbnail image.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                      | [writeByteBuffer](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#writeByteBuffer(java.io.OutputStream,%20android.util.Size,%20java.nio.ByteBuffer,%20kotlin.Long))`(`dngOutput:` `[OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)`, `size:` `[Size](https://developer.android.com/reference/kotlin/android/util/Size.html#)`, `pixels:` `[ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)`, `offset:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Write the[android.graphics.ImageFormat#RAW_SENSOR](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int)pixel data to a DNG file with the currently configured metadata.    |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                      | [writeImage](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#writeImage(java.io.OutputStream,%20android.media.Image))`(`dngOutput:` `[OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)`, `pixels:` `[Image](https://developer.android.com/reference/kotlin/android/media/Image.html#)`)` Write the pixel data to a DNG file with the currently configured metadata.                                                                                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                      | [writeInputStream](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#writeInputStream(java.io.OutputStream,%20android.util.Size,%20java.io.InputStream,%20kotlin.Long))`(`dngOutput:` `[OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)`, `size:` `[Size](https://developer.android.com/reference/kotlin/android/util/Size.html#)`, `pixels:` `[InputStream](https://developer.android.com/reference/kotlin/java/io/InputStream.html#)`, `offset:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Write the[android.graphics.ImageFormat#RAW_SENSOR](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int)pixel data to a DNG file with the currently configured metadata. |

|                                                                                         Protected methods                                                                                          ||
|------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [finalize](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#finalize())`()` <br /> |

## Constants

### MAX_THUMBNAIL_DIMENSION

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

```
static val MAX_THUMBNAIL_DIMENSION: Int
```

Max width or height dimension for thumbnails.  

    Value: 256

## Public constructors

### DngCreator

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

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

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[android.hardware.camera2.CaptureResult](https://developer.android.com/reference/kotlin/android/hardware/camera2/CaptureResult)object.

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

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

## Public methods

### close

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

```
fun close(): Unit
```

|                        Exceptions                        ||
|-----------------------|-----------------------------------|
| `java.lang.Exception` | if this resource cannot be closed |

### setDescription

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

```
fun setDescription(description: String): DngCreator
```

Set the user description string to write.

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

|                                                                        Parameters                                                                        ||
|---------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `description` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the user description string. This value cannot be`null`. |

|                                                                                                                                                                     Return                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | this[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult))object. This value cannot be`null`. |

### setLocation

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

```
fun setLocation(location: Location): DngCreator
```

Set image location metadata.

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

|                                                                                                                           Parameters                                                                                                                           ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `location` | [Location](https://developer.android.com/reference/kotlin/android/location/Location.html#):an[android.location.Location](https://developer.android.com/reference/kotlin/android/location/Location.html#)object to set. This value cannot be`null`. |

|                                                                                                                                                                     Return                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | this[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult))object. This value cannot be`null`. |

|                                                           Exceptions                                                            ||
|--------------------------------------|-------------------------------------------------------------------------------------------|
| `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.html#ApiLevels)  

```
fun setOrientation(orientation: Int): DngCreator
```

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.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `orientation` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the orientation value to set, one of: - [android.media.ExifInterface#ORIENTATION_NORMAL](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_NORMAL:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_FLIP_HORIZONTAL](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_FLIP_HORIZONTAL:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_ROTATE_180](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_ROTATE_180:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_FLIP_VERTICAL](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_FLIP_VERTICAL:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_TRANSPOSE](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_TRANSPOSE:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_ROTATE_90](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_ROTATE_90:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_TRANSVERSE](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_TRANSVERSE:kotlin.Int) - [android.media.ExifInterface#ORIENTATION_ROTATE_270](https://developer.android.com/reference/kotlin/android/media/ExifInterface.html#ORIENTATION_ROTATE_270:kotlin.Int) |

|                                                                                                                                                                     Return                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | this[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult))object. This value cannot be`null`. |

### setThumbnail

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

```
fun setThumbnail(pixels: Bitmap): DngCreator
```

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[MAX_THUMBNAIL_DIMENSION](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION:kotlin.Int)will be rejected.

|                                                                                                                     Parameters                                                                                                                      ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pixels` | [Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#):a[android.graphics.Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#)of pixel data. This value cannot be`null`. |

|                                                                                                                                                                     Return                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | this[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult))object. This value cannot be`null`. |

|                                                                                                                   Exceptions                                                                                                                    ||
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if the given thumbnail image has a dimension larger than[MAX_THUMBNAIL_DIMENSION](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION:kotlin.Int). |

### setThumbnail

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

```
fun setThumbnail(pixels: Image): DngCreator
```

Set the thumbnail image.

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

|                                                                                                                                                                                             Parameters                                                                                                                                                                                              ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pixels` | [Image](https://developer.android.com/reference/kotlin/android/media/Image.html#):an[android.media.Image](https://developer.android.com/reference/kotlin/android/media/Image.html#)object with the format[android.graphics.ImageFormat#YUV_420_888](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#YUV_420_888:kotlin.Int). This value cannot be`null`. |

|                                                                                                                                                                     Return                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#) | this[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#DngCreator(android.hardware.camera2.CameraCharacteristics,%20android.hardware.camera2.CaptureResult))object. This value cannot be`null`. |

|                                                                                                                   Exceptions                                                                                                                    ||
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if the given thumbnail image has a dimension larger than[MAX_THUMBNAIL_DIMENSION](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#MAX_THUMBNAIL_DIMENSION:kotlin.Int). |

### writeByteBuffer

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

```
fun writeByteBuffer(
    dngOutput: OutputStream, 
    size: Size, 
    pixels: ByteBuffer, 
    offset: Long
): Unit
```

Write the[android.graphics.ImageFormat#RAW_SENSOR](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int)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[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#)metadata tags, and will typically be equal to the width and height of[CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE:android.hardware.camera2.CameraCharacteristics.Key). Prior to API level 23, this was always the same as[CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE:android.hardware.camera2.CameraCharacteristics.Key). The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in[CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_COLOR_FILTER_ARRANGEMENT:android.hardware.camera2.CameraCharacteristics.Key). If insufficient metadata is available to write a well-formatted DNG file, an[java.lang.IllegalStateException](https://developer.android.com/reference/kotlin/java/lang/IllegalStateException.html#)will be thrown.

Any mark or limit set on this[ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)is ignored, and will be cleared by this method.

|                                                                                                                           Parameters                                                                                                                            ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dngOutput` | [OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#):an[java.io.OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)to write the DNG file to. This value cannot be`null`. |
| `size`      | [Size](https://developer.android.com/reference/kotlin/android/util/Size.html#):the[Size](https://developer.android.com/reference/kotlin/android/util/Size.html#)of the image to write, in pixels. This value cannot be`null`.                      |
| `pixels`    | [ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#):an[java.nio.ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)of pixel data to write. This value cannot be`null`.        |
| `offset`    | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):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                 |

|                                                       Exceptions                                                       ||
|-----------------------------------|-------------------------------------------------------------------------------------|
| `java.io.IOException`             | if an error was encountered in the input or output stream.                          |
| `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.html#ApiLevels)  

```
fun writeImage(
    dngOutput: OutputStream, 
    pixels: Image
): Unit
```

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

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

|                                                                                                                           Parameters                                                                                                                            ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dngOutput` | [OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#):an[java.io.OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)to write the DNG file to. This value cannot be`null`. |
| `pixels`    | [Image](https://developer.android.com/reference/kotlin/android/media/Image.html#):an[android.media.Image](https://developer.android.com/reference/kotlin/android/media/Image.html#)to write. This value cannot be`null`.                           |

|                                                        Exceptions                                                         ||
|--------------------------------------|-------------------------------------------------------------------------------------|
| `java.io.IOException`                | if an error was encountered in the output stream.                                   |
| `java.lang.IllegalArgumentException` | if an image with an unsupported format was used.                                    |
| `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.html#ApiLevels)  

```
fun writeInputStream(
    dngOutput: OutputStream, 
    size: Size, 
    pixels: InputStream, 
    offset: Long
): Unit
```

Write the[android.graphics.ImageFormat#RAW_SENSOR](https://developer.android.com/reference/kotlin/android/graphics/ImageFormat.html#RAW_SENSOR:kotlin.Int)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[DngCreator](https://developer.android.com/reference/kotlin/android/hardware/camera2/DngCreator#)metadata tags, and will typically be equal to the width and height of[CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE:android.hardware.camera2.CameraCharacteristics.Key). Prior to API level 23, this was always the same as[CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE:android.hardware.camera2.CameraCharacteristics.Key). The pixel layout in the input is determined from the reported color filter arrangement (CFA) set in[CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT](https://developer.android.com/reference/kotlin/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_COLOR_FILTER_ARRANGEMENT:android.hardware.camera2.CameraCharacteristics.Key). If insufficient metadata is available to write a well-formatted DNG file, an[java.lang.IllegalStateException](https://developer.android.com/reference/kotlin/java/lang/IllegalStateException.html#)will be thrown.

|                                                                                                                           Parameters                                                                                                                            ||
|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dngOutput` | [OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#):an[java.io.OutputStream](https://developer.android.com/reference/kotlin/java/io/OutputStream.html#)to write the DNG file to. This value cannot be`null`. |
| `size`      | [Size](https://developer.android.com/reference/kotlin/android/util/Size.html#):the[Size](https://developer.android.com/reference/kotlin/android/util/Size.html#)of the image to write, in pixels. This value cannot be`null`.                      |
| `pixels`    | [InputStream](https://developer.android.com/reference/kotlin/java/io/InputStream.html#):an[java.io.InputStream](https://developer.android.com/reference/kotlin/java/io/InputStream.html#)of pixel data to write. This value cannot be`null`.       |
| `offset`    | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):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                 |

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

## Protected methods

### finalize

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

```
protected fun finalize(): Unit
```

|                         Exceptions                         ||
|-----------------------|-------------------------------------|
| `java.lang.Throwable` | the`Exception`raised by this method |