Interface ICameraImageApi
This interface is typically implemented by platform-specific implementations of the XRCameraSubsystem
to support CameraImage.
End users do not need to implement this. Use
Namespace: UnityEngine.XR.ARExtensions
Syntax
public interface ICameraImageApi
Methods
ConvertAsync(Int32, CameraImageConversionParams)
Create an asynchronous request to convert a camera image, similar to TryConvert(Int32, CameraImageConversionParams, IntPtr, Int32) except the conversion should happen on a thread other than the calling (main) thread.
Declaration
int ConvertAsync(int nativeHandle, CameraImageConversionParams conversionParams)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the camera image to convert. |
CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use during the conversion. |
Returns
Type | Description |
---|---|
System.Int32 | A unique identifier for this request. |
ConvertAsync(Int32, CameraImageConversionParams, XRCameraExtensions.OnImageRequestCompleteDelegate, IntPtr)
Similar to ConvertAsync(Int32, CameraImageConversionParams) but takes a delegate to invoke when the request is complete, rather than returning a request id.
If the first parameter to callback is Ready
then the dataPtr
parameter must be valid for the duration of the invocation. The data may be destroyed
immediately upon return. The context parameter must be passed back to the callback.
Declaration
void ConvertAsync(int nativeHandle, CameraImageConversionParams conversionParams, XRCameraExtensions.OnImageRequestCompleteDelegate callback, IntPtr context)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the camera image to convert. |
CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use during the conversion. |
XRCameraExtensions.OnImageRequestCompleteDelegate | callback | A delegate which must be invoked when the request is complete, whether successfully or not. |
IntPtr | context | An |
DisposeAsyncRequest(Int32)
Dispose an existing async conversion request. See ConvertAsync(Int32, CameraImageConversionParams).
Declaration
void DisposeAsyncRequest(int requestId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | requestId | A unique identifier for the request. |
DisposeImage(Int32)
Dispose an existing CameraImage identified by nativeHandle.
Declaration
void DisposeImage(int nativeHandle)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for this camera image (see |
GetAsyncRequestStatus(Int32)
Get the status of an existing asynchronous conversion request. See ConvertAsync(Int32, CameraImageConversionParams).
Declaration
AsyncCameraImageConversionStatus GetAsyncRequestStatus(int requestId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | requestId | The unique identifier associated with a request. |
Returns
Type | Description |
---|---|
AsyncCameraImageConversionStatus | The state of the request. |
NativeHandleValid(Int32)
Determine whether a native image handle returned by
If a handle is valid, TryConvert(Int32, CameraImageConversionParams, IntPtr, Int32) and
Declaration
bool NativeHandleValid(int nativeHandle)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the camera image in question. |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryAcquireLatestImage(out Int32, out Vector2Int, out Int32, out Double, out CameraImageFormat)
Attempt to acquire the latest camera image. The camera image should be retained until DisposeImage(Int32) is called.
Declaration
bool TryAcquireLatestImage(out int nativeHandle, out Vector2Int dimensions, out int planeCount, out double timestamp, out CameraImageFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the latest camera image. |
Vector2Int | dimensions | The dimensions of the image. |
System.Int32 | planeCount | The number of planes in the image. |
System.Double | timestamp | The timestamp associated with this camera image. |
CameraImageFormat | format |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryConvert(Int32, CameraImageConversionParams, IntPtr, Int32)
Convert the image with handle nativeHandle using the provided CameraImageConversionParams.
Declaration
bool TryConvert(int nativeHandle, CameraImageConversionParams conversionParams, IntPtr destinationBuffer, int bufferLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the camera image to convert. |
CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use during the conversion. |
IntPtr | destinationBuffer | A buffer to write the converted image to. |
System.Int32 | bufferLength | The number of bytes available in the buffer. |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetAsyncRequestData(Int32, out IntPtr, out Int32)
Get a pointer to the image data from a completed asynchronous request. This method should only succeed if GetAsyncRequestStatus(Int32) returns Ready.
Declaration
bool TryGetAsyncRequestData(int requestId, out IntPtr dataPtr, out int dataLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | requestId | The unique identifier associated with a request. |
IntPtr | dataPtr | A pointer to the native buffer containing the data. |
System.Int32 | dataLength | The number of bytes in dataPtr. |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetConvertedDataSize(Int32, Vector2Int, TextureFormat, out Int32)
Get the number of bytes required to store an image with the given dimensions and TextureFormat
.
Declaration
bool TryGetConvertedDataSize(int nativeHandle, Vector2Int dimensions, TextureFormat format, out int size)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for the camera image to convert. |
Vector2Int | dimensions | The dimensions of the output image. |
TextureFormat | format | The |
System.Int32 | size | The number of bytes required to store the converted image. |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetPlane(Int32, Int32, out Int32, out Int32, out IntPtr, out Int32)
Attempt to get information about an image plane from a CameraImage by index.
Declaration
bool TryGetPlane(int nativeHandle, int planeIndex, out int rowStride, out int pixelStride, out IntPtr dataPtr, out int dataLength)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nativeHandle | A unique identifier for this camera image (see |
System.Int32 | planeIndex | The index of the plane to get. |
System.Int32 | rowStride | The number of bytes per row. |
System.Int32 | pixelStride | The number of bytes between pixels. |
IntPtr | dataPtr | A pointer to the native memory. |
System.Int32 | dataLength | The number of bytes pointed to by dataPtr. |
Returns
Type | Description |
---|---|
System.Boolean |