Exemple #1
0
        private static ImageCodecInfo[] GetInstalledCodecs(GetCodecDelegate getMethod)
        {
            ImagingFactory factory = new ImagingFactoryClass();

            uint   count;
            IntPtr pCodec;
            //int hResult = factory.GetInstalledEncoders(out count, out pCodec);
            int hResult = getMethod(out count, out pCodec);

            if (hResult != 0)
            {
                throw new System.ComponentModel.Win32Exception(hResult);
            }

            ImageCodecInfo        info = new ImageCodecInfo();
            List <ImageCodecInfo> list = new List <ImageCodecInfo>();

            for (int i = 0; i < count; i++)
            {
                IntPtr p = new IntPtr(pCodec.ToInt32() + (i * Marshal.SizeOf(info)));
                info = (ImageCodecInfo)Marshal.PtrToStructure(p, typeof(ImageCodecInfo));
                list.Add(info);
            }
            return(list.ToArray());
        }
Exemple #2
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;
                        }
                    }
                }
            }
        }
Exemple #3
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));
        }
Exemple #4
0
        static public IBitmapImage CreateThumbnail(Stream stream, Size size)
        {
            if (stream == null)
            {
                throw new ArgumentNullException();
            }

            ImagingFactory factory = new ImagingFactoryClass();
            IImage         image, imageThumb;

            factory.CreateImageFromStream(new StreamOnFile(stream), out image);
            image.GetThumbnail((uint)size.Width, (uint)size.Height, out imageThumb);
            IBitmapImage imageBitmap = null;
            ImageInfo    ii;

            image.GetImageInfo(out ii);
            factory.CreateBitmapFromImage(image, (uint)size.Width, (uint)size.Height, ii.PixelFormat, InterpolationHint.InterpolationHintDefault, out imageBitmap);
            return(imageBitmap);
        }
Exemple #5
0
        static public IBitmapImage BitmapToIImageBitmap(Bitmap bitmap)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException();
            }

            ImagingFactory factory = new ImagingFactoryClass();

            System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            IBitmapImage imageBitmap             = null;

            factory.CreateNewBitmap((uint)bd.Width, (uint)bd.Height, bd.PixelFormat, out imageBitmap);
            BitmapDataInternal bdi = new BitmapDataInternal();
            RECT rc = new RECT(0, 0, bd.Width, bd.Height);

            imageBitmap.LockBits(rc, (int)ImageLockMode.WriteOnly, bd.PixelFormat, ref bdi);
            int cb = bdi.Stride * bdi.Height;

            CopyMemory(bdi.Scan0, bd.Scan0, cb);
            bitmap.UnlockBits(bd);
            imageBitmap.UnlockBits(ref bdi);
            return(imageBitmap);
        }
Exemple #6
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;
                        }
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Gets all of the installed imaging decoders on the device
        /// </summary>
        /// <returns></returns>
        public static ImageCodecInfo[] GetInstalledDecoders()
        {
            ImagingFactory factory = new ImagingFactoryClass();

            return(GetInstalledCodecs(factory.GetInstalledDecoders));
        }