/// <summary> /// Attempt to get the latest camera image. This provides directly access to the raw /// pixel data, as well as utilities to convert to RGB and Grayscale formats. /// The <see cref="CameraImage"/> must be disposed to avoid resource leaks. /// </summary> /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param> /// <param name="cameraImage"></param> /// <returns></returns> public static bool TryGetLatestImage( this XRCameraSubsystem cameraSubsystem, out CameraImage cameraImage) { if (cameraSubsystem == null) { throw new ArgumentNullException("cameraSubsystem"); } int nativeHandle; Vector2Int dimensions; int planeCount; double timestamp; CameraImageFormat format; if (s_AsyncCameraImageApi.TryAcquireLatestImage(out nativeHandle, out dimensions, out planeCount, out timestamp, out format)) { cameraImage = new CameraImage(s_AsyncCameraImageApi, nativeHandle, dimensions, planeCount, timestamp, format); return(true); } else { cameraImage = default(CameraImage); return(false); } }
/// <summary> /// Constructs a <see cref="CameraImageConversionParams"/> using the <paramref name="image"/>'s full resolution. That is, /// it sets <see cref="inputRect"/> to <c>(0, 0, image.width, image.height)</c> and <see cref="outputDimensions"/> to <c>(image.width, image.height)</c>. /// </summary> /// <param name="image">The source <see cref="CameraImage"/>.</param> /// <param name="format">The <c>TextureFormat</c> to convert to.</param> /// <param name="transformation">An <see cref="CameraImageTransformation"/> to apply (optional).</param> public CameraImageConversionParams( CameraImage image, TextureFormat format, CameraImageTransformation transformation = CameraImageTransformation.None) { m_InputRect = new RectInt(0, 0, image.width, image.height); m_OutputDimensions = new Vector2Int(image.width, image.height); m_Format = format; m_Transformation = transformation; }