Photo

interface Photo extends HybridObject

Represents a captured Photo in-memory.

Photos can be captured with a CameraPhotoOutput, and can be saved to a file using saveToTemporaryFileAsync().

To display the photo to the user, use toImageAsync(), then display that using react-native-nitro-image's <NitroImage /> component.

Note

As with all in-memory objects holding large native memory such as Photos, Frames, Images or more, make sure to dispose() the Photo once you are no longer using it, as otherwise the JS Runtime might not immediately delete it, possibly exhausting system resources.

Examples

Display the Photo to the user using react-native-nitro-image:

const photoOutput = ...
const [image, setImage] = useState<Image>()

const takePhoto = async () => {
  const photo = await photoOutput.capturePhoto({}, {})
  const img = await photo.toImageAsync()
  setImage(img)
  photo.dispose()
}

return <NitroImage style={{ flex: 1 }} image={image} />

Save the photo to a temporary file:

const photoOutput = ...

const takePhoto = async () => {
  const photo = await photoOutput.capturePhoto({}, {})
  const image = await photo.toImageAsync()
  photo.dispose()
}

Convert the Photo to a Skia Image:

const photoOutput = ...
const photo = await photoOutput.capturePhoto({}, {})
const encodedData = await photo.getFileDataAsync()
const bytes = new Uint8Array(encodedData)
const data = Skia.Data.fromBytes(bytes)
const skiaImage = Skia.Image.MakeImageFromEncoded(data)
photo.dispose()

Properties

calibrationData?

iOS
readonly optional calibrationData: CameraCalibrationData

Get the associated CameraCalibrationData for this Photo if calibration data delivery was enabled.

See

CapturePhotoSettings.enableCameraCalibrationDataDelivery


containerFormat

readonly containerFormat: PhotoContainerFormat

Get the PhotoContainerFormat of this Photo.


depth?

readonly optional depth: Depth

Get the associated Depth data for this Photo if it has one.

See

CapturePhotoSettings.enableDepthData


hasPixelBuffer

readonly hasPixelBuffer: boolean

Get whether this Photo has a native pixel buffer attached to it, which allows reading its pixels from JS.

See

getPixelBuffer()


height

readonly height: number

Get the height of this Photo, in pixels.


isMirrored

readonly isMirrored: boolean

Gets whether this Photo is mirrored alongside the vertical axis.


isRawPhoto

readonly isRawPhoto: boolean

Gets whether this Photo is a RAW photo (i.e. no processing has been applied), or a processed photo (e.g. JPEG).

See

containerFormat


orientation

readonly orientation: CameraOrientation

Gets the CameraOrientation this Photo was captured in.

CameraOrientation will be applied lazily via EXIF flags, or when converting the Photo to an Image.


timestamp

readonly timestamp: number

Represents the timestamp this Photo was captured at, using the system's host clock, in seconds.


width

readonly width: number

Get the width of this Photo, in pixels.

Methods

getFileData()

getFileData(): ArrayBuffer

Gets the raw file data of the Photo after processing and including EXIF flags.


getFileDataAsync()

getFileDataAsync(): Promise<ArrayBuffer>

Asynchronously gets the raw file data of the Photo after processing and including EXIF flags.


getPixelBuffer()

getPixelBuffer(): ArrayBuffer

Get the Photo's native pixel buffer. This allows readonly access to the individual pixels.

This does not contain any EXIF data.

Throws

If hasPixelBuffer is false.


saveToFileAsync()

saveToFileAsync(path: string): Promise<void>

Asynchronously saves this Photo to a file at the given path, using this containerFormat.

Parameters

path

The path to save the Image to. Must contain a full path name including filename and extension. All parent directories must exist, but the file itself must not exist.


saveToTemporaryFileAsync()

saveToTemporaryFileAsync(): Promise<string>

Asynchronously saves this Photo to a temporary file using this containerFormat, and returns the path it was saved at.


toImage()

toImage(): Image

Converts this Photo to an Image, possibly applying orientation and isMirrored settings.

Throws

If the Photo is a raw photo (see isRawPhoto)

Throws

If the Photo's Image data cannot be accessed


toImageAsync()

toImageAsync(): Promise<Image>

Asynchronously converts this Photo to an Image, possibly applying orientation and isMirrored settings.

Throws

If the Photo is a raw photo (see isRawPhoto)

Throws

If the Photo's Image data cannot be accessed