示例#1
0
        public (int width, int height) GetSize(Stream inputContent)
        {
            using var input = DrImage.FromStream(inputContent);

            inputContent.Position = 0;
            using var imageReader = new ImagePropertyReader(inputContent);

            int width  = input.Width;
            int height = input.Height;

            ImagePropertyReader.Orientation?orientation = imageReader.FindOrientation();
            if (orientation != null)
            {
                switch (orientation.Value)
                {
                case ImagePropertyReader.Orientation.D270:
                case ImagePropertyReader.Orientation.D90:
                    int tmp = width;
                    width  = height;
                    height = tmp;
                    break;
                }
            }

            return(width, height);
        }
示例#2
0
        private void EnsureExifImageRotation(DrImage image, Stream imageContent)
        {
            imageContent.Position = 0;
            using (var imageReader = new ImagePropertyReader(imageContent))
            {
                ImagePropertyReader.Orientation?orientation = imageReader.FindOrientation();
                if (orientation != null)
                {
                    switch (orientation.Value)
                    {
                    case ImagePropertyReader.Orientation.D270:
                        image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        break;

                    case ImagePropertyReader.Orientation.D180:
                        image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        break;

                    case ImagePropertyReader.Orientation.D90:
                        image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        break;
                    }
                }
            }
        }
示例#3
0
        private void SetProperties(Image entity, Stream imageContent, bool isWhenIncluded = true)
        {
            using (ImagePropertyReader propertyReader = new ImagePropertyReader(imageContent))
            {
                entity.Location.Longitude = propertyReader.FindLongitude();
                entity.Location.Latitude  = propertyReader.FindLatitude();
                entity.Location.Altitude  = propertyReader.FindAltitude();

                if (isWhenIncluded)
                {
                    DateTime?when = propertyReader.FindTakenWhen();
                    if (when != null)
                    {
                        entity.When = when.Value;
                    }
                }
            }
        }