Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeifContext"/> class, with the specified byte array to read from.
        /// </summary>
        /// <param name="bytes">A byte array that contains the HEIF image.</param>
        /// <exception cref="ArgumentNullException"><paramref name="bytes"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="bytes"/> is an empty array.</exception>
        /// <exception cref="HeifException">
        /// Unable to create the native HeifContext.
        ///
        /// -or-
        ///
        /// The LibHeif version is not supported.
        ///
        /// -or-
        ///
        /// A LibHeif error occurred.
        /// </exception>
        public HeifContext(byte[] bytes)
        {
            Validate.IsNotNullOrEmptyArray(bytes, nameof(bytes));
            LibHeifVersion.ThrowIfNotSupported();

            this.context = CreateNativeContext();
            try
            {
                this.readerStreamIO = HeifStreamFactory.CreateFromMemory(bytes);
                InitializeContextFromReader();
            }
            catch
            {
                this.context.Dispose();
                this.readerStreamIO?.Dispose();
                throw;
            }
        }