/// <summary>
 /// Constructs a <see cref="XRCameraImageConversionParams"/> 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="XRCameraImage"/>.</param>
 /// <param name="format">The <c>TextureFormat</c> to convert to.</param>
 /// <param name="transformation">An optional <see cref="CameraImageTransformation"/> to apply.</param>
 public XRCameraImageConversionParams(
     XRCameraImage 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;
 }
Пример #2
0
        /// <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.
        /// </summary>
        /// <remarks>
        /// The returned <see cref="XRCameraImage"/> must be disposed to avoid resource leaks.
        /// </remarks>
        /// <param name="cameraImage">A valid <see cref="XRCameraImage"/> if this method returns <c>true</c>.</param>
        /// <returns>
        /// <c>true</c> if the image was acquired. Otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.NotSupportedException">Thrown if the implementation does not support camera image.
        /// </exception>
        public bool TryGetLatestImage(out XRCameraImage cameraImage)
        {
            CameraImageCinfo cameraImageCinfo;

            if (m_Provider.TryAcquireLatestImage(out cameraImageCinfo))
            {
                cameraImage = new XRCameraImage(this, cameraImageCinfo.nativeHandle, cameraImageCinfo.dimensions,
                                                cameraImageCinfo.planeCount, cameraImageCinfo.timestamp,
                                                cameraImageCinfo.format);
                return(true);
            }
            else
            {
                cameraImage = default(XRCameraImage);
                return(false);
            }
        }