コード例 #1
0
        public void DecodeJpeg(string fileName)
        {
            const int ExecutionCount = 30;

            if (!Vector.IsHardwareAccelerated)
            {
                throw new Exception("Vector.IsHardwareAccelerated == false! ('prefer32 bit' enabled?)");
            }

            string path = TestFile.GetPath(fileName);

            byte[] bytes = File.ReadAllBytes(path);

            this.Measure(
                ExecutionCount,
                () =>
            {
                Image img = Image.Load(bytes);
            },
                // ReSharper disable once ExplicitCallerInfoArgument
                $"Decode {fileName}");
        }
コード例 #2
0
        public void ImageShouldFlip(RotateType rotateType, FlipType flipType, ushort orientation)
        {
            string path = CreateOutputDirectory("AutoOrient");

            TestFile file = TestFile.Create(TestImages.Bmp.F);

            Image image = file.CreateImage();

            image.ExifProfile = new ExifProfile();
            image.ExifProfile.SetValue(ExifTag.Orientation, orientation);

            using (FileStream before = File.OpenWrite($"{path}/before-{file.FileName}"))
            {
                using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}"))
                {
                    image.RotateFlip(rotateType, flipType)
                    .Save(before)
                    .AutoOrient()
                    .Save(after);
                }
            }
        }
コード例 #3
0
ファイル: GifEncoderTests.cs プロジェクト: vovgou/ImageSharp
        public void Encode_IgnoreMetadataIsTrue_CommentsAreNotWritten()
        {
            GifEncoderOptions options = new GifEncoderOptions()
            {
                IgnoreMetadata = true
            };

            TestFile testFile = TestFile.Create(TestImages.Gif.Rings);

            using (Image input = testFile.CreateImage())
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    input.SaveAsGif(memStream, options);

                    memStream.Position = 0;
                    using (Image output = Image.Load(memStream))
                    {
                        Assert.Equal(0, output.MetaData.Properties.Count);
                    }
                }
            }
        }
コード例 #4
0
        public void Encode_IgnoreMetadataIsFalse_ExifProfileIsWritten()
        {
            EncoderOptions options = new EncoderOptions()
            {
                IgnoreMetadata = false
            };

            TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);

            using (Image input = testFile.CreateImage())
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    input.Save(memStream, new JpegFormat(), options);

                    memStream.Position = 0;
                    using (Image output = Image.Load(memStream))
                    {
                        Assert.NotNull(output.MetaData.ExifProfile);
                    }
                }
            }
        }
コード例 #5
0
        public void Encode_IgnoreMetadataIsTrue_ExifProfileIgnored()
        {
            JpegEncoderOptions options = new JpegEncoderOptions()
            {
                IgnoreMetadata = true
            };

            TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);

            using (Image input = testFile.CreateImage())
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    input.SaveAsJpeg(memStream, options);

                    memStream.Position = 0;
                    using (Image output = Image.Load(memStream))
                    {
                        Assert.Null(output.MetaData.ExifProfile);
                    }
                }
            }
        }
コード例 #6
0
ファイル: ExifProfileTests.cs プロジェクト: vovgou/ImageSharp
        public void SetValue()
        {
            Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

            Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage();

            image.MetaData.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");

            ExifValue value = image.MetaData.ExifProfile.GetValue(ExifTag.Software);

            TestValue(value, "ImageSharp");

            Assert.Throws <ArgumentException>(() => { value.Value = 15; });

            image.MetaData.ExifProfile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);

            TestValue(value, new SignedRational(7555, 100));

            Assert.Throws <ArgumentException>(() => { value.Value = 75; });

            image.MetaData.ExifProfile.SetValue(ExifTag.XResolution, new Rational(150.0));

            // We also need to change this value because this overrides XResolution when the image is written.
            image.MetaData.HorizontalResolution = 150.0;

            value = image.MetaData.ExifProfile.GetValue(ExifTag.XResolution);
            TestValue(value, new Rational(150, 1));

            Assert.Throws <ArgumentException>(() => { value.Value = "ImageSharp"; });

            image.MetaData.ExifProfile.SetValue(ExifTag.ReferenceBlackWhite, null);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
            TestValue(value, (string)null);

            image.MetaData.ExifProfile.SetValue(ExifTag.GPSLatitude, latitude);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.GPSLatitude);
            TestValue(value, latitude);

            image = WriteAndRead(image);

            Assert.NotNull(image.MetaData.ExifProfile);
            Assert.Equal(17, image.MetaData.ExifProfile.Values.Count());

            value = image.MetaData.ExifProfile.GetValue(ExifTag.Software);
            TestValue(value, "ImageSharp");

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
            TestValue(value, new SignedRational(75.55));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.XResolution);
            TestValue(value, new Rational(150.0));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
            Assert.Null(value);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.GPSLatitude);
            TestValue(value, latitude);

            image.MetaData.ExifProfile.Parts = ExifParts.ExifTags;

            image = WriteAndRead(image);

            Assert.NotNull(image.MetaData.ExifProfile);
            Assert.Equal(8, image.MetaData.ExifProfile.Values.Count());

            Assert.NotNull(image.MetaData.ExifProfile.GetValue(ExifTag.ColorSpace));
            Assert.True(image.MetaData.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.False(image.MetaData.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.Null(image.MetaData.ExifProfile.GetValue(ExifTag.ColorSpace));

            Assert.Equal(7, image.MetaData.ExifProfile.Values.Count());
        }