Esempio n. 1
0
        public static System.Drawing.Image OrientImage(System.Drawing.Image image)
        {
            int orientationId = 0x0112;

            if (image.PropertyIdList.Contains(orientationId))
            {
                int rotationValue = image.GetPropertyItem(0x0112).Value[0];
                switch (rotationValue)
                {
                case 1:     // landscape, do nothing
                    break;

                case 8:     // rotated 90 right
                            // de-rotate:
                    image.RotateFlip(rotateFlipType: System.Drawing.RotateFlipType.Rotate270FlipNone);
                    break;

                case 3:     // bottoms up
                    image.RotateFlip(rotateFlipType: System.Drawing.RotateFlipType.Rotate180FlipNone);
                    break;

                case 6:     // rotated 90 left
                    image.RotateFlip(rotateFlipType: System.Drawing.RotateFlipType.Rotate90FlipNone);
                    break;
                }
                image.RemovePropertyItem(orientationId);
            }

            return(image);
        }
Esempio n. 2
0
        /// <summary>
        /// байты->System.Drawing.Image
        /// </summary>
        /// <param name="byteArrayIn"></param>
        /// <returns></returns>
        //image from byte
        public static System.Drawing.Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);

            System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
            foreach (var i in returnImage.PropertyItems)
            {
                returnImage.RemovePropertyItem(i.Id);
            }

            return(returnImage);
        }