Ejemplo n.º 1
0
        static AnimatedImage()
        {
            Bitmap emptyBitmap = new Bitmap(1, 1);

            emptyBitmap.SetPixel(0, 0, Color.Transparent);
            emptyImage = new AnimatedImage(emptyBitmap);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Importer"/> class,
        /// featuring support for the default image formats JPG/JPEG, PNG,
        /// (animated) GIF, BMP and TIF/TIFF.
        /// </summary>
        public Importer()
        {
            ImportImage defaultImporter = delegate(string path)
            {
                if (path == null)
                {
                    throw new ArgumentNullException("path");
                }

                Image source = Image.FromFile(path);

                //Downscale big images right in the importer to improve
                //performance (only if image is not animated).
                double scaleFactor = Math.Min(1,
                                              (double)MaxPixels / (source.Width * source.Height));

                if (AnimatedImage.GetFrameCount(source) > 1 ||
                    scaleFactor == 1.0 ||
                    !DownscaleOversizedImages)
                {
                    return(source);
                }

                try
                {
                    Image image = new Bitmap((int)(source.Width * scaleFactor),
                                             (int)(source.Height * scaleFactor));

                    using (Graphics graphics = Graphics.FromImage(image))
                    {
                        graphics.InterpolationMode =
                            InterpolationMode.HighQualityBicubic;
                        graphics.DrawImage(source, 0, 0, image.Width,
                                           image.Height);
                    }

                    return(image);
                }
                finally
                {
                    if (source != null)
                    {
                        source.Dispose();
                    }
                }
            };

            importers.Add("jpg", defaultImporter);
            importers.Add("jpeg", defaultImporter);
            importers.Add("png", defaultImporter);
            importers.Add("gif", defaultImporter);
            importers.Add("bmp", defaultImporter);
            importers.Add("tif", defaultImporter);
            importers.Add("tiff", defaultImporter);
        }