public virtual async Task <ActionResult> Details(string id)
        {
            var          cts  = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());
            JpegMetadata data = null;

            try
            {
                var repository = FileSystemGenericRepositoryFactory.CreateJpegMetadataRepositoryReadOnly(cts.Token, PhysicalPath, IncludeSubDirectories);

                data = await repository.MetadataGetByPathAsync(id.Replace("/", "\\"));

                if (data == null)
                {
                    return(HandleReadException());
                }
            }
            catch
            {
                return(HandleReadException());
            }

            ViewBag.PageTitle = Title;
            ViewBag.Admin     = Admin;

            var dto = Mapper.Map <JpegMetadataDto>(data);

            return(View("Details", dto));
        }
        public virtual ActionResult Edit(string id, JpegMetadataDto dto)
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            if (ModelState.IsValid)
            {
                try
                {
                    var metadata = new JpegMetadata(PhysicalPath + id.Replace("/", "\\"));
                    Mapper.Map(dto, metadata);

                    var lat = metadata.Latitude;

                    metadata.SaveWithCaption(dto.Caption, dto.DateCreated);

                    //await Service.UpdateAsync(dto, cts.Token);
                    return(RedirectToControllerDefault().WithSuccess(this, Messages.UpdateSuccessful));
                }
                catch (Exception ex)
                {
                    HandleUpdateException(ex);
                }
            }

            ViewBag.PageTitle = Title;
            ViewBag.Admin     = Admin;
            return(View("Edit", dto));
        }
コード例 #3
0
 public void Decode_DetectsCorrectColorType <TPixel>(TestImageProvider <TPixel> provider, JpegColorType expectedColorType)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage(JpegDecoder))
     {
         JpegMetadata meta = image.Metadata.GetJpegMetadata();
         Assert.Equal(expectedColorType, meta.ColorType);
     }
 }
コード例 #4
0
        public void Quality_BothComponentsQuality()
        {
            int quality = 50;

            var meta = new JpegMetadata {
                LuminanceQuality = quality, ChrominanceQuality = quality
            };

            Assert.Equal(meta.Quality, quality);
        }
コード例 #5
0
        public void Quality_LuminanceOnlyQuality()
        {
            int quality = 50;

            var meta = new JpegMetadata {
                LuminanceQuality = quality
            };

            Assert.Equal(meta.Quality, quality);
        }
コード例 #6
0
        public void Quality_ReturnsMaxQuality()
        {
            int qualityLuma   = 50;
            int qualityChroma = 30;

            var meta = new JpegMetadata {
                LuminanceQuality = qualityLuma, ChrominanceQuality = qualityChroma
            };

            Assert.Equal(meta.Quality, qualityLuma);
        }
コード例 #7
0
        public void Identify_DetectsCorrectColorType(string imagePath, JpegColorType expectedColorType)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                IImageInfo   image = JpegDecoder.Identify(Configuration.Default, stream);
                JpegMetadata meta  = image.Metadata.GetJpegMetadata();
                Assert.Equal(expectedColorType, meta.ColorType);
            }
        }
コード例 #8
0
        public void CloneIsDeep()
        {
            var meta = new JpegMetadata {
                Quality = 50
            };
            var clone = (JpegMetadata)meta.DeepClone();

            clone.Quality = 99;

            Assert.False(meta.Quality.Equals(clone.Quality));
        }
コード例 #9
0
        public void Identify_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                var          decoder = new JpegDecoder();
                IImageInfo   image   = decoder.Identify(Configuration.Default, stream);
                JpegMetadata meta    = image.Metadata.GetJpegMetadata();
                Assert.Equal(quality, meta.Quality);
            }
        }
コード例 #10
0
        public void CloneIsDeep()
        {
            var meta = new JpegMetadata {
                Quality = 50, ColorType = JpegColorType.Luminance
            };
            var clone = (JpegMetadata)meta.DeepClone();

            clone.Quality   = 99;
            clone.ColorType = JpegColorType.YCbCrRatio420;

            Assert.False(meta.Quality.Equals(clone.Quality));
            Assert.False(meta.ColorType.Equals(clone.ColorType));
        }
コード例 #11
0
        public void Decode_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                using (Image image = JpegDecoder.Decode(Configuration.Default, stream))
                {
                    JpegMetadata meta = image.Metadata.GetJpegMetadata();
                    Assert.Equal(quality, meta.Quality);
                }
            }
        }
コード例 #12
0
        public void Decode_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                var decoder = new JpegDecoder();
                using (Image <Rgba32> image = decoder.Decode <Rgba32>(Configuration.Default, stream))
                {
                    JpegMetadata meta = image.Metadata.GetFormatMetadata(JpegFormat.Instance);
                    Assert.Equal(quality, meta.Quality);
                }
            }
        }
コード例 #13
0
        public void Encode_PreservesColorType <TPixel>(TestImageProvider <TPixel> provider, JpegColorType expectedColorType)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // arrange
            using Image <TPixel> input = provider.GetImage(JpegDecoder);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, JpegEncoder);

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(expectedColorType, meta.ColorType);
        }
コード例 #14
0
        public void Encode_PreservesQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (Image <Rgba32> input = testFile.CreateRgba32Image())
            {
                using (var memStream = new MemoryStream())
                {
                    input.Save(memStream, JpegEncoder);

                    memStream.Position = 0;
                    using (var output = Image.Load <Rgba32>(memStream))
                    {
                        JpegMetadata meta = output.Metadata.GetJpegMetadata();
                        Assert.Equal(quality, meta.Quality);
                    }
                }
            }
        }
コード例 #15
0
        public void Encode_WithUnsupportedColorType_FromInputImage_DefaultsToYCbCr420 <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // arrange
            using Image <TPixel> input = provider.GetImage(JpegDecoder);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, new JpegEncoder()
            {
                Quality = 75
            });

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(JpegColorType.YCbCrRatio420, meta.ColorType);
        }
コード例 #16
0
        public void Encode_WithUnsupportedColorType_DefaultsToYCbCr420(JpegColorType colorType)
        {
            // arrange
            var jpegEncoder = new JpegEncoder()
            {
                ColorType = colorType
            };

            using var input        = new Image <Rgb24>(10, 10);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, jpegEncoder);

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(JpegColorType.YCbCrRatio420, meta.ColorType);
        }
コード例 #17
0
ファイル: JpegMetadata.cs プロジェクト: yvanoff/ImageSharp
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegMetadata"/> class.
 /// </summary>
 /// <param name="other">The metadata to create an instance from.</param>
 private JpegMetadata(JpegMetadata other)
 {
     this.Quality   = other.Quality;
     this.ColorType = other.ColorType;
 }
コード例 #18
0
ファイル: JpegMetaData.cs プロジェクト: zoonware/ImageSharp
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegMetadata"/> class.
 /// </summary>
 /// <param name="other">The metadata to create an instance from.</param>
 private JpegMetadata(JpegMetadata other) => this.Quality = other.Quality;
コード例 #19
0
        public JpegMetadata MapFileInfoToJpegMetadata(FileInfo fileInfo)
        {
            var metadata = new JpegMetadata(fileInfo.FullName, _physicalPath);

            return(metadata);
        }
コード例 #20
0
        public void Quality_DefaultQuality()
        {
            var meta = new JpegMetadata();

            Assert.Equal(meta.Quality, ImageSharp.Formats.Jpeg.Components.Quantization.DefaultQualityFactor);
        }