示例#1
0
        /// <summary>
        /// Get the number of bytes required to store a converted image with the given parameters.
        /// </summary>
        /// <param name="dimensions">The desired dimensions of the converted image.</param>
        /// <param name="format">The desired <c>TextureFormat</c> for the converted image.</param>
        /// <returns>The number of bytes required to store the converted image.</returns>
        /// <exception cref="System.ArgumentException">Thrown if the desired <paramref name="format"/> is not
        /// supported.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the desired <paramref name="dimensions"/>
        /// exceed the native image dimensions.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the image is invalid.</exception>
        /// <seealso cref="FormatSupported"/>
        public int GetConvertedDataSize(Vector2Int dimensions, TextureFormat format)
        {
            ValidateNativeHandleAndThrow();

            if (dimensions.x > this.dimensions.x)
            {
                throw new ArgumentOutOfRangeException("width",
                                                      string.Format("Converted image width must be less than or equal to native image width. {0} > {1}",
                                                                    dimensions.x, this.dimensions.x));
            }

            if (dimensions.y > this.dimensions.y)
            {
                throw new ArgumentOutOfRangeException("height",
                                                      string.Format("Converted image height must be less than or equal to native image height. {0} > {1}",
                                                                    dimensions.y, this.dimensions.y));
            }

            if (!FormatSupported(format))
            {
                throw new ArgumentException("Invalid texture format.", "format");
            }

            int size;

            if (!m_CameraSubsystem.TryGetConvertedDataSize(m_NativeHandle, dimensions, format, out size))
            {
                throw new InvalidOperationException("XRCameraImage is not valid.");
            }

            return(size);
        }