Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeifContext"/> class, with the specified file to read from.
        /// </summary>
        /// <param name="path">The file to read from.</param>
        /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="path"/> is empty, contains only whitespace or contains invalid characters.
        /// </exception>
        /// <exception cref="FileNotFoundException">The file specified by <paramref name="path"/> does not exist.</exception>
        /// <exception cref="HeifException">
        /// Unable to create the native HeifContext.
        ///
        /// -or-
        ///
        /// The LibHeif version is not supported.
        ///
        /// -or-
        ///
        /// A LibHeif error occurred.
        /// </exception>
        /// <exception cref="IOException">An I/O error occurred.</exception>
        /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
        /// <exception cref="UnauthorizedAccessException">
        /// The access requested is not permitted by the operating system for the specified path.
        /// </exception>
        public HeifContext(string path)
        {
            Validate.IsNotNull(path, nameof(path));
            LibHeifVersion.ThrowIfNotSupported();

            this.context = CreateNativeContext();
            try
            {
                this.readerStreamIO = HeifStreamFactory.CreateFromFile(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                InitializeContextFromReader();
            }
            catch
            {
                this.context.Dispose();
                this.readerStreamIO?.Dispose();
                throw;
            }
        }
Esempio n. 2
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;
            }
        }