/// <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)); }
/// <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 async Task <Image <TPixel> > DecodeAsync <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { var decoder = new PngDecoderCore(configuration, this); try { return(await decoder.DecodeAsync <TPixel>(stream).ConfigureAwait(false)); } 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); } }