private static void SetDimensions(IFocalPointData focalPointData)
 {
     if (!focalPointData.IsReadOnly && focalPointData.BinaryData != null)
     {
         using (var stream = focalPointData.BinaryData.OpenRead()) {
             try {
                 var size = ImageDimensionService.GetDimensions(stream);
                 if (size.IsValid)
                 {
                     if (focalPointData.OriginalHeight != size.Height)
                     {
                         Logger.Information($"Setting height for {focalPointData.Name} to {size.Height}.");
                         focalPointData.OriginalHeight = size.Height;
                     }
                     if (focalPointData.OriginalWidth != size.Width)
                     {
                         Logger.Information($"Setting width for {focalPointData.Name} to {size.Width}.");
                         focalPointData.OriginalWidth = size.Width;
                     }
                 }
                 else
                 {
                     Logger.Information($"Could not read size of {focalPointData.Name}.");
                 }
             } catch (Exception ex) {
                 Logger.Error($"Could not read size of {focalPointData.Name}, data might be corrupt.", ex);
             }
         }
     }
 }
Esempio n. 2
0
        public void GetDimensions_StreamContainsNonImageFile_ReturnsSizeEmpty()
        {
            using (var stream = File.OpenRead("..\\..\\TestData\\nonimage.pdf")) {
                var size = ImageDimensionService.GetDimensions(stream);

                size.IsValid.ShouldBe(false);
            }
        }
Esempio n. 3
0
        public void GetDimensions_StreamContainsFileOfType_ReturnsCorrectSize(string extension)
        {
            using (var stream = File.OpenRead($"..\\..\\TestData\\FileTypes\\TestImage.{extension}")) {
                var size = ImageDimensionService.GetDimensions(stream);

                size.IsValid.ShouldBe(true);
                size.Width.ShouldBe(500);
                size.Height.ShouldBe(500);
            }
        }
Esempio n. 4
0
        public void GetDimensions_StreamContainsJpeg_ReturnsCorrectSize(string fileNamePart)
        {
            var dimensions     = fileNamePart.Split(new[] { 'x' }, StringSplitOptions.RemoveEmptyEntries);
            var expectedWidth  = int.Parse(dimensions[0]);
            var expectedHeight = int.Parse(dimensions[1]);

            using (var stream = File.OpenRead($"..\\..\\TestData\\Dimensions\\{fileNamePart}.jpg")) {
                var size = ImageDimensionService.GetDimensions(stream);
                size.IsValid.ShouldBe(true);
                size.Width.ShouldBe(expectedWidth);
                size.Height.ShouldBe(expectedHeight);
            }
        }
Esempio n. 5
0
        public void ImageDimensionService_GetDimensions()
        {
            var  stopWatch  = new Stopwatch();
            long memoryUsed = 0;

            stopWatch.Start();
            {
                var memoryCheckPoint1 = dotMemory.Check();
                foreach (var file in fixture.Files)
                {
                    using (var stream = file.OpenRead()) {
                        var size = ImageDimensionService.GetDimensions(stream);
                    }
                }
                var memoryCheckPoint2 = dotMemory.Check(memory => {
                    memoryUsed = memory.GetTrafficFrom(memoryCheckPoint1).AllocatedMemory.SizeInBytes;
                });
            }
            stopWatch.Stop();
            testOutputHelper.WriteLine($"Using {nameof(ImageDimensionService.GetDimensions)} to get size of {fixture.Files.Count()} images took {stopWatch.ElapsedMilliseconds} ms. Memory used was {memoryUsed} bytes.");
            Assert.True(true);
        }
Esempio n. 6
0
        public void GetDimensions_StreamCannotRead_ThrowsException()
        {
            Action action = () => ImageDimensionService.GetDimensions(Stream.Null);

            action.ShouldThrow <ArgumentNullException>();
        }