Пример #1
0
        /// <summary>
        /// Читает угол поворота из EXIF
        /// </summary>
        /// <param name="file"></param>
        /// <param name="exifRotationAngle"></param>
        public static void ReadRotationAngleFromEXIF(string file, out RotationAngle exifRotationAngle)
        {
            exifRotationAngle = RotationAngle.Zero;

            using (StreamOnFile newStreamOnFile = new StreamOnFile(file))
            {
                IImageDecoder newIImageDecoder;

                OpenNETCF.Drawing.Imaging.IImagingFactory newImagingFactory = new OpenNETCF.Drawing.Imaging.ImagingFactoryClass();

                int r = newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagNone, out newIImageDecoder);

                // Ниже используется своя функция обработки EXIF, так как на Philips попытка проверить
                // jpeg из-за некорректных данных рушится в COM. Это случается из-за параметра DecoderInitFlag.DecoderInitFlagNone
                // ImageProperty[] items = ImageUtils.GetAllProperties(newIImageDecoder);
                ImageProperty[] items = GetAllPropertiesInternal(newIImageDecoder);
                if (items.Length == 0)
                {
                    newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagBuiltIn1st, out newIImageDecoder);
                    items = GetAllPropertiesInternal(newIImageDecoder);
                }

                foreach (ImageProperty item in items)
                {
                    if (item.Id == ImageTag.TAG_ORIENTATION)
                    {
                        try
                        {
                            switch (Convert.ToInt16(item.GetValue()))
                            {
                            case 3:
                                exifRotationAngle = RotationAngle.Clockwise180;
                                break;

                            case 6:
                                exifRotationAngle = RotationAngle.Clockwise90;
                                break;

                            case 8:
                                exifRotationAngle = RotationAngle.Clockwise270;
                                break;

                            default:
                                throw new Exception();
                                break;
                            }
                        }
                        catch (Exception)
                        {
                            exifRotationAngle = RotationAngle.Zero;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Loads specified image property from the given image
        /// </summary>
        /// <param name="imagePath">path to the image file</param>
        /// <param name="property">Property tag</param>
        /// <returns>Property</returns>
        public static ImageProperty LoadProperty(string imagePath, ImageTag property)
        {
            if (imagePath == null)
            {
                throw new ArgumentNullException();
            }

            StreamOnFile   st      = new StreamOnFile(imagePath);
            IImageDecoder  decoder = null;
            ImagingFactory factory = new ImagingFactoryClass();

            factory.CreateImageDecoder(st, DecoderInitFlag.DecoderInitFlagNone, out decoder);
            return(LoadProperty(decoder, property));
        }
Пример #3
0
        /// <summary>
        /// Читает угол поворота из EXIF
        /// </summary>
        /// <param name="file"></param>
        /// <param name="exifRotationAngle"></param>
        public static void ReadRotationAngleFromEXIF(string file, out RotationAngle exifRotationAngle)
        {
            exifRotationAngle = RotationAngle.Zero;

            using (StreamOnFile newStreamOnFile = new StreamOnFile(file))
            {
                IImageDecoder newIImageDecoder;

                OpenNETCF.Drawing.Imaging.IImagingFactory newImagingFactory = new OpenNETCF.Drawing.Imaging.ImagingFactoryClass();

                int r = newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagNone, out newIImageDecoder);

                // Ниже используется своя функция обработки EXIF, так как на Philips попытка проверить
                // jpeg из-за некорректных данных рушится в COM. Это случается из-за параметра DecoderInitFlag.DecoderInitFlagNone
                // ImageProperty[] items = ImageUtils.GetAllProperties(newIImageDecoder);
                ImageProperty[] items = GetAllPropertiesInternal(newIImageDecoder);
                if (items.Length == 0)
                {
                    newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagBuiltIn1st, out newIImageDecoder);
                    items = GetAllPropertiesInternal(newIImageDecoder);
                }

                foreach (ImageProperty item in items)
                {
                    if (item.Id == ImageTag.TAG_ORIENTATION)
                    {
                        try
                        {
                            switch (Convert.ToInt16(item.GetValue()))
                            {
                                case 3:
                                    exifRotationAngle = RotationAngle.Clockwise180;
                                    break;

                                case 6:
                                    exifRotationAngle = RotationAngle.Clockwise90;
                                    break;

                                case 8:
                                    exifRotationAngle = RotationAngle.Clockwise270;
                                    break;

                                default:
                                    throw new Exception();
                                    break;
                            }
                        }
                        catch (Exception)
                        {
                            exifRotationAngle = RotationAngle.Zero;
                        }
                    }
                }
            }
        }