Ejemplo n.º 1
0
        private static Image <Rgba32> WriteAndReadWebp(Image <Rgba32> image, WebpFileFormatType fileFormat)
        {
            using (var memStream = new MemoryStream())
            {
                image.SaveAsWebp(memStream, new WebpEncoder()
                {
                    FileFormat = fileFormat
                });
                image.Dispose();

                memStream.Position = 0;
                return(Image.Load <Rgba32>(memStream, new WebpDecoder()));
            }
        }
Ejemplo n.º 2
0
        public void Encode_PreserveRatio <TPixel>(TestImageProvider <TPixel> provider, WebpFileFormatType expectedFormat)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            var options = new WebpEncoder();

            using Image <TPixel> input = provider.GetImage();
            using var memoryStream = new MemoryStream();
            input.Save(memoryStream, options);

            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);

            ImageMetadata meta         = output.Metadata;
            WebpMetadata  webpMetaData = meta.GetWebpMetadata();

            Assert.Equal(expectedFormat, webpMetaData.FileFormat);
        }