コード例 #1
0
 private void cbFormats_SelectedIndexChanged(object sender, EventArgs e)
 {
     _currentFormatPreset = (FormatPreset)cbFormats.SelectedItem;
     if (Initialized)
     {
         updatePreview();
     }
 }
コード例 #2
0
 public FormatPreset(string Name, string FormatName, long?QualityLevel, long?ColorDepth)
 {
     if (FormatName == "SRC")
     {
         Original = this;
     }
     this.Name         = Name;
     this.FormatName   = FormatName;
     this.QualityLevel = (QualityLevel == null ? -1 : (long)QualityLevel);
     this.ColorDepth   = (ColorDepth == null ? -1 : (long)ColorDepth);
 }
コード例 #3
0
        public ImageWorkUI()
        {
            InitializeComponent();

            cbFormats.DataSource    = new BindingSource(FormatPreset.ComboBoxOptions, null);
            cbFormats.DisplayMember = "Name";
            _currentFormatPreset    = FormatPreset.Original;

            cbResolutions.DataSource    = new BindingSource(ResolutionPreset.ComboBoxOptions, null);
            cbResolutions.DisplayMember = "Name";
            _currentResolutionPreset    = ResolutionPreset.Original;
        }
コード例 #4
0
 private void btnApply_Click(object sender, EventArgs e)
 {
     if (chkSetJPGQualityLevel.Checked)
     {
         FormatPreset format = (FormatPreset)cbQualityLevel.SelectedItem;
         foreach (ImageWorkUI iwui in imageWorkUIs)
         {
             // SetJPEGQuality only applies to JPEGs
             iwui.SetJPEGQuality((int)format.QualityLevel);
         }
     }
     this.Close();
 }
コード例 #5
0
 public void SetJPEGQuality(int QualityLevel)
 {
     if (_currentFormatPreset.FormatName == "JPG")
     {
         FormatPreset result = FormatPreset.ComboBoxOptions.FirstOrDefault(opt => (opt.FormatName == "JPG") && (opt.QualityLevel == QualityLevel));
         if (result == null)
         {
             // Find nearest %
             int NewQualityLevel = (int)((float)Math.Round(QualityLevel / (float)10) * 10);
             SetJPEGQuality(NewQualityLevel);
             //result = new FormatPreset("JPEG " + QualityLevel + "%", "JPG", QualityLevel, 24);
             //FormatPreset.ComboBoxOptions.Add(result);
             return;
         }
         cbFormats.SelectedItem = result;
     }
 }
コード例 #6
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;
        }