コード例 #1
0
        /// <summary>
        /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
        /// </summary>
        /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public async Task <IMagickImage <QuantumType> > CreateAsync(string fileName, IPixelReadSettings <QuantumType> settings, CancellationToken cancellationToken)
        {
            var image = new MagickImage();
            await image.ReadPixelsAsync(fileName, settings, cancellationToken).ConfigureAwait(false);

            return(image);
        }
コード例 #2
0
ファイル: MagickImage.cs プロジェクト: lonelyxmas/Magick.NET
        /// <summary>
        /// Read single image frame from pixel data.
        /// </summary>
        /// <param name="stream">The stream to read the image data from.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public async Task ReadPixelsAsync(Stream stream, IPixelReadSettings <QuantumType>?settings, CancellationToken cancellationToken)
        {
            Throw.IfNullOrEmpty(nameof(stream), stream);

            var bytes = await Bytes.CreateAsync(stream, cancellationToken).ConfigureAwait(false);

            ReadPixels(bytes.GetData(), 0, bytes.Length, settings);
        }
コード例 #3
0
        /// <summary>
        /// Read single image frame from pixel data.
        /// </summary>
        /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public async Task ReadPixelsAsync(string fileName, IPixelReadSettings <QuantumType>?settings, CancellationToken cancellationToken)
        {
            var filePath = FileHelper.CheckForBaseDirectory(fileName);

            Throw.IfNullOrEmpty(nameof(fileName), filePath);

            var data = await File.ReadAllBytesAsync(filePath, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            ReadPixels(data, 0, data.Length, settings);
        }
コード例 #4
0
        /// <summary>
        /// Read single image frame.
        /// </summary>
        /// <param name="data">The span of quantum to read the image data from.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void ReadPixels(ReadOnlySpan <QuantumType> data, IPixelReadSettings <QuantumType>?settings)
        {
            Throw.IfEmpty(nameof(data), data);
            Throw.IfNull(nameof(settings), settings);
            Throw.IfTrue(nameof(settings), string.IsNullOrEmpty(settings.Mapping), "Pixel storage mapping should be defined.");
            Throw.IfTrue(nameof(settings), settings.StorageType != StorageType.Quantum, $"Storage type should be {nameof(StorageType.Quantum)}.");

            var newReadSettings = CreateReadSettings(settings.ReadSettings);

            SetSettings(newReadSettings);

            var count          = data.Length;
            var expectedLength = GetExpectedLength(settings);

            Throw.IfTrue(nameof(data), count < expectedLength, "The count is " + count + " but should be at least " + expectedLength + ".");

            _nativeInstance.ReadPixels(settings.ReadSettings.Width !.Value, settings.ReadSettings.Height !.Value, settings.Mapping, settings.StorageType, data, 0);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="data">The byte array to read the image data from.</param>
 /// <param name="offset">The offset at which to begin reading data.</param>
 /// <param name="count">The maximum number of bytes to read.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(byte[] data, int offset, int count, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(data, offset, count, settings);
コード例 #6
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(string fileName, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(fileName, settings);
コード例 #7
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="stream">The stream to read the image data from.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(Stream stream, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(stream, settings);
コード例 #8
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="file">The file to read the image from.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(FileInfo file, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(file, settings);
コード例 #9
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="data">The byte array to read the image data from.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(byte[] data, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(data, settings);
コード例 #10
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="data">The span of bytes to read the image data from.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public IMagickImage <QuantumType> Create(ReadOnlySpan <byte> data, IPixelReadSettings <QuantumType> settings)
 => new MagickImage(data, settings);
コード例 #11
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public Task <IMagickImage <QuantumType> > CreateAsync(string fileName, IPixelReadSettings <QuantumType> settings)
 => CreateAsync(fileName, settings, CancellationToken.None);
コード例 #12
0
 /// <summary>
 /// Read single image frame from pixel data.
 /// </summary>
 /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public Task ReadPixelsAsync(string fileName, IPixelReadSettings <QuantumType>?settings)
 => ReadPixelsAsync(fileName, settings, CancellationToken.None);
コード例 #13
0
        /// <summary>
        /// Read single image frame from pixel data.
        /// </summary>
        /// <param name="file">The file to read the image from.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public Task ReadPixelsAsync(FileInfo file, IPixelReadSettings <QuantumType>?settings, CancellationToken cancellationToken)
        {
            Throw.IfNull(nameof(file), file);

            return(ReadPixelsAsync(file.FullName, settings, cancellationToken));
        }
コード例 #14
0
ファイル: MagickImage.cs プロジェクト: lonelyxmas/Magick.NET
 /// <summary>
 /// Read single image frame from pixel data.
 /// </summary>
 /// <param name="stream">The stream to read the image data from.</param>
 /// <param name="settings">The pixel settings to use when reading the image.</param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
 /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
 public Task ReadPixelsAsync(Stream stream, IPixelReadSettings <QuantumType>?settings)
 => ReadPixelsAsync(stream, settings, CancellationToken.None);