Esempio n. 1
0
        private void updatePreview()
        {
            if ((_currentFormatPreset == FormatPreset.Original) && (_currentResolutionPreset == ResolutionPreset.Original))
            {
                Optimized = Original;
            }
            else
            {
                if (_currentFormatPreset.FormatName == "PNG")
                {
                    Optimized = Original.GenerateOptimized_PNG(_currentFormatPreset.ColorDepth, _currentResolutionPreset);
                }
                else if (_currentFormatPreset.FormatName == "JPG")
                {
                    Optimized = Original.GenerateOptimized_JPEG(_currentFormatPreset.QualityLevel, _currentResolutionPreset);
                }
                else
                {
                    // Original format, but scaled
                    Optimized = Original.GenerateOptimized_JPEG(100, _currentResolutionPreset);
                }
            }

            pbOptimized.Image       = Optimized.Image;
            pbOptimized.MaximumSize = new Size(Optimized.Width, Optimized.Height);
            lblOptimizedImage.Text  = "Optimized Image: " + Optimized.GetShortInfo();

            if (OptimizedChanged != null)
            {
                OptimizedChanged(this, new EventArgs());
            }
        }
Esempio n. 2
0
        public ImageWorkUI(string imageFile, XmlNode relationshipXmlNode) : this()
        {
            Original  = new ImageWithInfo(imageFile);
            Optimized = Original;

            this.RelationshipNode = relationshipXmlNode;

            // Automatic recommendation - set the upper max resolution to 1600x900 and change to 80% JPEG
            if ((Original.Width > 1600) || (Original.Height > 900))
            {
                _currentResolutionPreset = ResolutionPreset.ComboBoxOptions.First(opt => (opt.Width == 1600) && (opt.Height == 900));
                _currentFormatPreset     = FormatPreset.ComboBoxOptions.First(opt => (opt.FormatName == "JPG") && (opt.QualityLevel == 80));
            }
            cbResolutions.SelectedItem = _currentResolutionPreset;

            // Automatic recommendation - if pixel-byte density is higher than 20% and the format is PNG, convert to a 70% JPG
            if ((Original.BytesPerPixel > 0.2) && (Original.Type == ImageWithInfo.ImageTypes.Png) && (_currentFormatPreset == FormatPreset.Original))
            {
                _currentFormatPreset = FormatPreset.ComboBoxOptions.First(opt => (opt.FormatName == "JPG") && (opt.QualityLevel == 70));
            }

            // If we're scaling a JPG, try to preserve the quality (use 80% instead of 70%)
            //if ((_currentResolutionPreset != ResolutionPreset.Original) && (Original.Type == ImageWithInfo.ImageTypes.Jpg))
            //{
            //    _currentFormatPreset = FormatPreset.ComboBoxOptions.First(opt => (opt.FormatName == "JPG") && (opt.QualityLevel == 80));
            //}

            cbFormats.SelectedItem = _currentFormatPreset;

            // Set up originals
            pbOriginal.Image        = Original.Image;
            pbOptimized.Image       = Original.Image; // This will get updated with the optimized image when initialization is done
            pbOriginal.MaximumSize  = new Size(Original.Width, Original.Height);
            pbOptimized.MaximumSize = pbOriginal.MaximumSize;
            int[] scaledSizes = Original.GetScaledSizeFromWidth(pbOriginal.Size.Width);
            pbOriginal.Size  = new Size(scaledSizes[0], scaledSizes[1]);
            pbOptimized.Size = new Size(scaledSizes[0], scaledSizes[1]);

            // Populate info about the original file
            lblOriginalImage.Text = "Original Image: " + Original.GetShortInfo();

            // Finished
            Initialized = true;
        }