/// <summary> /// Read all image frames. /// </summary> /// <param name="data">The span of bytes to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public void Read(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings) { Throw.IfEmpty(nameof(data), data); Clear(); AddImages(data, readSettings, false); }
/// <summary> /// Read only metadata and not the pixel data from all image frames. /// </summary> /// <param name="data">The sequence of bytes to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public void Ping(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType>?readSettings) { Throw.IfEmpty(nameof(data), data); Clear(); AddImages(data, readSettings, true); }
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings, CancellationToken cancellationToken) { var image = new MagickImage(); await image.ReadAsync(fileName, readSettings, cancellationToken).ConfigureAwait(false); return(image); }
/// <summary> /// Read all image frames. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <param name="readSettings">The 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 ReadAsync(Stream stream, IMagickReadSettings <QuantumType>?readSettings, CancellationToken cancellationToken) { var bytes = await Bytes.CreateAsync(stream, cancellationToken).ConfigureAwait(false); Clear(); AddImages(bytes.GetData(), 0, bytes.Length, readSettings, false); }
internal MagickReadSettings(IMagickReadSettings <QuantumType> settings) { Copy(settings); ApplyDefines(); ApplyDimensions(); ApplyFrame(); }
/// <summary> /// Read single image frame. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <param name="readSettings">The 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 ReadAsync(Stream stream, IMagickReadSettings <QuantumType>?readSettings, CancellationToken cancellationToken) { Throw.IfNull(nameof(stream), stream); var bytes = await Bytes.CreateAsync(stream, cancellationToken).ConfigureAwait(false); Read(bytes.GetData(), readSettings); }
private void AddImages(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings, bool ping) { var settings = CreateSettings(readSettings); settings.Ping = ping; var result = _nativeInstance.ReadBlob(settings, data, 0, data.Length); AddImages(result, settings); }
/// <summary> /// Read all image frames. /// </summary> /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param> /// <param name="readSettings">The 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 ReadAsync(string fileName, IMagickReadSettings <QuantumType>?readSettings, CancellationToken cancellationToken) { Throw.IfNullOrEmpty(nameof(fileName), fileName); var bytes = await File.ReadAllBytesAsync(fileName, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); Clear(); AddImages(bytes, 0, bytes.Length, readSettings, false); }
/// <summary> /// Read single image frame. /// </summary> /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param> /// <param name="readSettings">The 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 ReadAsync(string fileName, IMagickReadSettings <QuantumType>?readSettings, CancellationToken cancellationToken) { var filePath = FileHelper.CheckForBaseDirectory(fileName); Throw.IfNullOrEmpty(nameof(fileName), filePath); var bytes = await File.ReadAllBytesAsync(fileName, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); Read(bytes, readSettings, false, fileName); }
private void Read(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings, bool ping, string?fileName = null) { var newReadSettings = CreateReadSettings(readSettings); SetSettings(newReadSettings); _settings.Ping = ping; _settings.FileName = fileName; _nativeInstance.ReadBlob(_settings, data, 0, data.Length); ResetSettings(); }
private void AddImages(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType>?readSettings, bool ping) { if (data.IsSingleSegment) { AddImages(data.FirstSpan, readSettings, ping); return; } var settings = CreateSettings(readSettings); settings.Ping = ping; settings.FileName = null; var wrapper = new ReadOnlySequenceWrapper(data); var reader = new ReadWriteStreamDelegate(wrapper.Read); var seeker = new SeekStreamDelegate(wrapper.Seek); var teller = new TellStreamDelegate(wrapper.Tell); var result = _nativeInstance.ReadStream(settings, reader, seeker, teller); AddImages(result, settings); }
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(fileName, readSettings);
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(stream, readSettings);
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(file, readSettings);
/// <summary> /// Read single image frame. /// </summary> /// <param name="data">The sequence of bytes to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public void Read(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType>?readSettings) { Throw.IfEmpty(nameof(data), data); Read(data, readSettings, false); }
/// <summary> /// Read all image frames. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <param name="readSettings">The 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 ReadAsync(Stream stream, IMagickReadSettings <QuantumType>?readSettings) => ReadAsync(stream, readSettings, CancellationToken.None);
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(data, readSettings);
/// <summary> /// Initializes a new instance that implements <see cref="IMagickImageCollection{TQuantumType}"/>. /// </summary> /// <param name="data">The sequence of bytes to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <returns>A new <see cref="IMagickImageCollection{TQuantumType}"/> instance.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public IMagickImageCollection <QuantumType> Create(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType> readSettings) => new MagickImageCollection(data, readSettings);
/// <summary> /// Initializes a new instance that implements <see cref="IMagickImageCollection{TQuantumType}"/>. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <returns>A new <see cref="IMagickImageCollection{TQuantumType}"/> instance.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public Task <IMagickImageCollection <QuantumType> > CreateAsync(Stream stream, IMagickReadSettings <QuantumType> readSettings) => CreateAsync(stream, readSettings, CancellationToken.None);
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(data, offset, count, readSettings);
/// <summary> /// Reads only metadata and not the pixel data. /// </summary> /// <param name="data">The span of bytes to read the information from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public void Ping(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings) { Throw.IfEmpty(nameof(data), data); Read(data, readSettings, true); }
/// <summary> /// Read all image frames. /// </summary> /// <param name="file">The file to read the frames from.</param> /// <param name="readSettings">The 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 ReadAsync(FileInfo file, IMagickReadSettings <QuantumType>?readSettings) => ReadAsync(file, readSettings, CancellationToken.None);
/// <summary> /// Read all image frames. /// </summary> /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param> /// <param name="readSettings">The 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 ReadAsync(string fileName, IMagickReadSettings <QuantumType>?readSettings) => ReadAsync(fileName, readSettings, CancellationToken.None);
/// <summary> /// Read all image frames. /// </summary> /// <param name="file">The file to read the frames from.</param> /// <param name="readSettings">The 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 ReadAsync(FileInfo file, IMagickReadSettings <QuantumType>?readSettings, CancellationToken cancellationToken) { Throw.IfNull(nameof(file), file); return(ReadAsync(file.FullName, readSettings, cancellationToken)); }
/// <summary> /// Initializes a new instance of the <see cref="IMagickImage{TQuantumType}"/> class. /// </summary> /// <param name="data">The byte array to read the image data from.</param> /// <param name="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => new MagickImage(data, readSettings);
/// <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="readSettings">The 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, IMagickReadSettings <QuantumType> readSettings) => CreateAsync(fileName, readSettings, CancellationToken.None);
/// <summary> /// Initializes a new instance that implements <see cref="IMagickImageCollection{TQuantumType}"/>. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>A new <see cref="IMagickImageCollection{TQuantumType}"/> instance.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public async Task <IMagickImageCollection <QuantumType> > CreateAsync(Stream stream, IMagickReadSettings <QuantumType> readSettings, CancellationToken cancellationToken) { var images = new MagickImageCollection(); await images.ReadAsync(stream, readSettings, cancellationToken).ConfigureAwait(false); return(images); }
/// <summary> /// Initializes a new instance that implements <see cref="IMagickImageCollection{TQuantumType}"/>. /// </summary> /// <param name="file">The file to read the image from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <returns>A new <see cref="IMagickImageCollection{TQuantumType}"/> instance.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public Task <IMagickImageCollection <QuantumType> > CreateAsync(FileInfo file, IMagickReadSettings <QuantumType> readSettings) => CreateAsync(file, readSettings, CancellationToken.None);