Пример #1
0
        public ImageDimensions CalculateImageDimensions(GooglePhotosMediaItem image, int maxWidth, int maxHeight)
        {
            if (maxWidth <= 0)
            {
                maxWidth = 1024;
            }
            if (maxHeight <= 0)
            {
                maxHeight = 768;
            }

            var imageWidth  = Convert.ToInt32(image.MediaMetadata.Width);
            var imageHeight = Convert.ToInt32(image.MediaMetadata.Height);

            var ratioX = (double)maxWidth / imageWidth;
            var ratioY = (double)maxHeight / imageHeight;
            var ratio  = Math.Min(ratioX, ratioY);

            var imageDimensions = new ImageDimensions
            {
                Height = (int)(imageHeight * ratio),
                Width  = (int)(imageWidth * ratio)
            };

            return(imageDimensions);
        }
Пример #2
0
        public void CalculateImageDimensions_Returns_CorrectDimensions(int photoWidth, int photoHeight, int maxWidth, int maxHeight, int expectedWidth, int expectedHeight)
        {
            // Arrange
            var photo = new GooglePhotosMediaItem
            {
                MediaMetadata = new GooglePhotosMediaMetaData
                {
                    Width = photoWidth.ToString(), Height = photoHeight.ToString()
                }
            };

            // Act

            var result = PhotoUtilities.CalculateImageDimensions(photo, maxWidth, maxHeight);

            // Assert
            Assert.That(result.Height, Is.EqualTo(expectedHeight), $"Calculated Height of {photoHeight} does not equal exptected height of {expectedHeight}");
            Assert.That(result.Width, Is.EqualTo(expectedWidth), $"Calculated Height of {photoWidth} does not equal exptected height of {expectedWidth}");
        }