Photo
interface Photo extends HybridObjectRepresents 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.
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)
}
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()
}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)Properties
calibrationData?
readonly optional calibrationData: CameraCalibrationDataGet the associated CameraCalibrationData
for this Photo if calibration data delivery
was enabled.
See
CapturePhotoSettings.enableCameraCalibrationDataDelivery
containerFormat
readonly containerFormat: PhotoContainerFormatGet the PhotoContainerFormat of
this Photo.
depth?
readonly optional depth: DepthGet the associated Depth data
for this Photo if it has one.
See
CapturePhotoSettings.enableDepthData
hasPixelBuffer
readonly hasPixelBuffer: booleanGet whether this Photo has
a native pixel buffer attached to it,
which allows reading its pixels from JS.
See
height
readonly height: numberGet the height of this Photo, in pixels.
isMirrored
readonly isMirrored: booleanGets whether this Photo is mirrored alongside the
vertical axis.
isRawPhoto
readonly isRawPhoto: booleanGets whether this Photo is a RAW photo (i.e.
no processing has been applied), or a processed photo (e.g.
JPEG).
See
orientation
readonly orientation: OrientationGets the Orientation this Photo was
captured in.
Orientation will be applied lazily via EXIF
flags, or when converting the Photo to an
Image.
timestamp
readonly timestamp: numberRepresents the timestamp this Photo was
captured at, using the system's host clock, in seconds.
width
readonly width: numberGet the width of this Photo, in pixels.
Methods
getFileData()
getFileData(): ArrayBufferGets the raw file data of the Photo after
processing and including EXIF flags.
getFileDataAsync()
getFileDataAsync(): Promise<ArrayBuffer>Asynchronously ets the raw file data of
the Photo after processing
and including EXIF flags.
getPixelBuffer()
getPixelBuffer(): ArrayBufferGet 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(): ImageConverts 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()
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