Esempio n. 1
0
        /// <summary>Constructs a new <see cref="ImageFileInfo" /> instance by reading the metadata from an image file header.</summary>
        /// <param name="imgPath">The path to the image file.</param>
        public static ImageFileInfo Load(string imgPath)
        {
            var fi = new FileInfo(imgPath);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("File not found", imgPath);
            }

            using var fs       = File.OpenRead(imgPath);
            using var stb      = new StreamBufferInjector(fs);
            using var ctx      = new PipelineContext(new ProcessImageSettings());
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(fs));

            return(fromWicImage(ctx, fi.Length, fi.LastWriteTimeUtc));
        }
        /// <inheritdoc cref="ProcessImage(string, Stream, ProcessImageSettings)" />
        /// <param name="imgStream">A stream containing a supported input image container. The stream must allow Seek and Read.</param>
        public static ProcessImageResult ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            checkInStream(imgStream);
            checkOutStream(outStream);

            using var stb      = new StreamBufferInjector(imgStream);
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(imgStream));

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }