コード例 #1
0
ファイル: PngDecoder.cs プロジェクト: xiawei666/ImageSharp
        /// <summary>
        /// Decodes the image from the specified stream to the <see cref="ImageFrame{TPixel}"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="configuration">The configuration for the image.</param>
        /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
        /// <returns>The decoded image.</returns>
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : struct, IPixel <TPixel>
        {
            var decoder = new PngDecoderCore(configuration, this);

            return(decoder.Decode <TPixel>(stream));
        }
コード例 #2
0
        /// <inheritdoc/>
        public Task <IImageInfo> IdentifyAsync(Configuration configuration, Stream stream)
        {
            var decoder = new PngDecoderCore(configuration, this);

            using var bufferedStream = new BufferedReadStream(configuration, stream);
            return(decoder.IdentifyAsync(bufferedStream));
        }
コード例 #3
0
        /// <inheritdoc/>
        public Task <Image <TPixel> > DecodeAsync <TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            var decoder = new PngDecoderCore(configuration, this);

            return(decoder.DecodeAsync <TPixel>(configuration, stream, cancellationToken));
        }
コード例 #4
0
ファイル: PngDecoder.cs プロジェクト: tkggand/ImageSharp
        /// <summary>
        /// Decodes the image from the specified stream to the <see cref="ImageFrame{TPixel}"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="configuration">The configuration for the image.</param>
        /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
        /// <returns>The decoded image.</returns>
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            var decoder = new PngDecoderCore(configuration, this);

            try
            {
                return(decoder.Decode <TPixel>(stream));
            }
            catch (InvalidMemoryOperationException ex)
            {
                Size dims = decoder.Dimensions;

                // TODO: use InvalidImageContentException here, if we decide to define it
                // https://github.com/SixLabors/ImageSharp/issues/1110
                throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
            }
        }
コード例 #5
0
ファイル: PngDecoder.cs プロジェクト: wilka/ImageSharp
        /// <summary>
        /// Decodes the image from the specified stream to the <see cref="ImageFrame{TPixel}"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="configuration">The configuration for the image.</param>
        /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
        /// <returns>The decoded image.</returns>
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            var decoder = new PngDecoderCore(configuration, this);

            try
            {
                return(decoder.Decode <TPixel>(stream));
            }
            catch (InvalidMemoryOperationException ex)
            {
                Size dims = decoder.Dimensions;

                PngThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);

                // Not reachable, as the previous statement will throw a exception.
                return(null);
            }
        }
コード例 #6
0
ファイル: PngDecoder.cs プロジェクト: wilka/ImageSharp
        /// <inheritdoc/>
        public Task <IImageInfo> IdentifyAsync(Configuration configuration, Stream stream)
        {
            var decoder = new PngDecoderCore(configuration, this);

            return(decoder.IdentifyAsync(stream));
        }
コード例 #7
0
ファイル: PngDecoder.cs プロジェクト: wilka/ImageSharp
        /// <inheritdoc/>
        public IImageInfo Identify(Configuration configuration, Stream stream)
        {
            var decoder = new PngDecoderCore(configuration, this);

            return(decoder.Identify(stream));
        }
コード例 #8
0
        /// <inheritdoc/>
        public Task <IImageInfo> IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken)
        {
            var decoder = new PngDecoderCore(configuration, this);

            return(decoder.IdentifyAsync(configuration, stream, cancellationToken));
        }