/// <summary> /// Convert the <c>XRCameraImage</c> to one of the supported formats using the specified /// <paramref name="conversionParams"/>. /// </summary> /// <param name="conversionParams">The parameters for the image conversion.</param> /// <param name="destinationBuffer">A pointer to memory to which to write the converted image.</param> /// <param name="bufferLength">The number of bytes pointed to by <paramref name="destinationBuffer"/>. Must be /// greater than or equal to the value returned by /// <see cref="GetConvertedDataSize(XRCameraImageConversionParams)"/>.</param> /// <exception cref="System.ArgumentException">Thrown if the <paramref name="bufferLength"/> is smaller than /// the data size required by the conversion.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the conversion failed.</exception> /// <seealso cref="FormatSupported"/> public void Convert(XRCameraImageConversionParams conversionParams, IntPtr destinationBuffer, int bufferLength) { ValidateNativeHandleAndThrow(); ValidateConversionParamsAndThrow(conversionParams); int requiredDataSize = GetConvertedDataSize(conversionParams); if (bufferLength < requiredDataSize) { throw new ArgumentException(string.Format( "Conversion requires {0} bytes but only provided {1} bytes.", requiredDataSize, bufferLength), "bufferLength"); } if (!m_CameraSubsystem.TryConvert(m_NativeHandle, conversionParams, destinationBuffer, bufferLength)) { throw new InvalidOperationException("Conversion failed."); } }