Struct CameraImage
Represents a single, raw image from a device camera. Provides access to the raw image plane data, as well
as conversion methods to convert to color and grayscale formats. See Convert(CameraImageConversionParams, IntPtr, Int32)
and ConvertAsync(CameraImageConversionParams).
Use CameraImage.
CameraImages must be explicitly disposed. Failing to do so will leak resources and could prevent future camera image access.
Inherited Members
Namespace: UnityEngine.XR.ARExtensions
Syntax
public struct CameraImage : IDisposable, IEquatable<CameraImage>
Properties
dimensions
The dimensions (width and height) of the image.
Declaration
public Vector2Int dimensions { get; }
Property Value
| Type | Description |
|---|---|
| Vector2Int |
format
The format used by the image planes. You will only need this if you plan to interpret the raw plane data.
Declaration
public CameraImageFormat format { get; }
Property Value
| Type | Description |
|---|---|
| CameraImageFormat |
height
The image height.
Declaration
public int height { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
planeCount
The number of image planes. A "plane" in this context refers to a channel in the raw video format, not a physical surface.
Declaration
public int planeCount { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
timestamp
The timestamp, in seconds, associated with this camera image
Declaration
public double timestamp { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
valid
Returns true if this CameraImage represents a valid image (i.e., not Disposed).
Declaration
public bool valid { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
width
The image width.
Declaration
public int width { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
Convert(CameraImageConversionParams, IntPtr, Int32)
Convert the CameraImage to one of the supported formats (see FormatSupported(TextureFormat))
using the specified conversionParams.
Declaration
public void Convert(CameraImageConversionParams conversionParams, IntPtr destinationBuffer, int bufferLength)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use for the conversion. |
| IntPtr | destinationBuffer | A pointer to memory to write the converted image to. |
| System.Int32 | bufferLength | The number of bytes pointed to by destinationBuffer. Must be greater than or equal to the value returned by GetConvertedDataSize(CameraImageConversionParams). |
ConvertAsync(CameraImageConversionParams)
Convert the CameraImage to one of the supported formats (see FormatSupported(TextureFormat))
using the specified conversionParams. The conversion is performed asynchronously. Use the returned
AsyncCameraImageConversion to check for the status of the conversion, and retrieve the data when complete.
It is safe to Dispose the CameraImage before the asynchronous operation has completed.
Declaration
public AsyncCameraImageConversion ConvertAsync(CameraImageConversionParams conversionParams)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use for the conversion. |
Returns
| Type | Description |
|---|---|
| AsyncCameraImageConversion | A new AsyncCameraImageConversion which can be used to check the status of the conversion operation and get the resulting data. |
ConvertAsync(CameraImageConversionParams, Action<AsyncCameraImageConversionStatus, CameraImageConversionParams, NativeArray<Byte>>)
Convert the CameraImage to one of the supported formats (see FormatSupported(TextureFormat))
using the specified conversionParams. The conversion is performed asynchronously, and onComplete
is invoked when the conversion is complete, whether successful or not.
The NativeArray provided in the onComplete delegate is only valid during the invocation and is disposed
immediately upon return.
Declaration
public void ConvertAsync(CameraImageConversionParams conversionParams, Action<AsyncCameraImageConversionStatus, CameraImageConversionParams, NativeArray<byte>> onComplete)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use for the conversion. |
| Action<AsyncCameraImageConversionStatus, CameraImageConversionParams, NativeArray<System.Byte>> | onComplete | A delegate to invoke when the conversion operation completes. The delegate is always invoked. |
Dispose()
Dispose native resources associated with this request, including the raw image data.
Any CameraImagePlanes returned by GetPlane(Int32) are invalidated immediately
after calling Dispose.
Declaration
public void Dispose()
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Overrides
Equals(CameraImage)
Declaration
public bool Equals(CameraImage other)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImage | other |
Returns
| Type | Description |
|---|---|
| System.Boolean |
FormatSupported(TextureFormat)
Determines whether the given TextureFormat is supported for conversion.
Declaration
public static bool FormatSupported(TextureFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureFormat | format | A
|
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
GetConvertedDataSize(CameraImageConversionParams)
Get the number of bytes required to store a converted image with the given parameters.
Declaration
public int GetConvertedDataSize(CameraImageConversionParams conversionParams)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImageConversionParams | conversionParams | The CameraImageConversionParams to use for the conversion. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of bytes required to store the converted image. |
GetConvertedDataSize(Vector2Int, TextureFormat)
Get the number of bytes required to store a converted image with the given parameters. Throws if the inputs are invalid.
Declaration
public int GetConvertedDataSize(Vector2Int dimensions, TextureFormat format)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2Int | dimensions | The dimensions of the converted image. |
| TextureFormat | format | The |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of bytes required to store the converted image. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
GetPlane(Int32)
Get an image "plane". A "plane" in this context refers to a channel in the raw video format, not a physical surface. Throws if the plane is invalid.
Declaration
public CameraImagePlane GetPlane(int planeIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | planeIndex | The index of the plane to get. |
Returns
| Type | Description |
|---|---|
| CameraImagePlane | A CameraImagePlane describing the plane. |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Overrides
Operators
Equality(CameraImage, CameraImage)
Declaration
public static bool operator ==(CameraImage lhs, CameraImage rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImage | lhs | |
| CameraImage | rhs |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(CameraImage, CameraImage)
Declaration
public static bool operator !=(CameraImage lhs, CameraImage rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| CameraImage | lhs | |
| CameraImage | rhs |
Returns
| Type | Description |
|---|---|
| System.Boolean |