HistogramUserControl.cs
Description du code
HistogramUserControl.cs est un fichier du projet PhotoBrol.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/photobrol/.
Projet PhotoBrol :
Editeur d'images en CSharp.
Code source ou contenu du fichier
Code c# (HistogramUserControl.cs) (196 lignes)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using be.gaudry.photobrol.model.image; using be.gaudry.photobrol.view.controls.histogram; using be.gaudry.model.config; namespace be.gaudry.photobrol.view.controls { public partial class HistogramUserControl : UserControl { private int currentImageHash = 0; private static Color[] colors; private ImageStatistics stat; private be.gaudry.model.math.Histogram activeHistogram; public HistogramUserControl() { Color.FromArgb(192, 0, 0), Color.FromArgb(0, 192, 0), Color.FromArgb(0, 0, 192), Color.FromArgb(128, 128, 128), }; activeHistogram = null; InitializeComponent(); "Histogrammes", this.Name, "http://www.cst.fr/IMG/pdf/Les_mesures_sur_les_images_numeriques.pdf", "Informations sur les histogrammes" ) ); } // Gather image statistics public void GatherStatistics(Bitmap image) { // avoid calculation in the case of the same image if (image != null) { if (currentImageHash == image.GetHashCode()) return; currentImageHash = image.GetHashCode(); } if (image != null) System.Diagnostics.Debug.WriteLine("=== Gathering histogram"); // busy Capture = true; Cursor = Cursors.WaitCursor; // get statistics // free Cursor = Cursors.Arrow; Capture = false; // clean combo channelCombo.Items.Clear(); channelCombo.Enabled = false; if (stat != null) { if (!stat.IsGrayscale) { // RGB picture channelCombo.Enabled = true; } else { // grayscale picture channelCombo.Items.Add("Gris"); } channelCombo.SelectedIndex = 0; } else { histogram.Values = null; meanLabel.Text = String.Empty; stdDevLabel.Text = String.Empty; medianLabel.Text = String.Empty; minLabel.Text = String.Empty; maxLabel.Text = String.Empty; levelLabel.Text = String.Empty; countLabel.Text = String.Empty; percentileLabel.Text = String.Empty; } } // selection changed in channels combo private void channelCombo_SelectedIndexChanged(object sender, System.EventArgs e) { if (stat != null) { SwitchChannel((stat.IsGrayscale) ? 3 : channelCombo.SelectedIndex); } } // Switch channel public void SwitchChannel(int channel) { if ((channel >= 0) && (channel <= 2)) { if (!stat.IsGrayscale) { histogram.Color = colors[channel]; activeHistogram = (channel == 0) ? stat.Red : (channel == 1) ? stat.Green : stat.Blue; } } else if (channel == 3) { if (stat.IsGrayscale) { histogram.Color = colors[3]; activeHistogram = stat.Gray; } } if (activeHistogram != null) { histogram.Values = activeHistogram.Values; meanLabel.Text = activeHistogram.Mean.ToString("F2"); stdDevLabel.Text = activeHistogram.StdDev.ToString("F2"); medianLabel.Text = activeHistogram.Median.ToString(); minLabel.Text = activeHistogram.Min.ToString(); maxLabel.Text = activeHistogram.Max.ToString(); } } // Cursor position changed over the histogram private void histogram_PositionChanged(object sender, HistogramEventArgs e) { int pos = e.Position; if (pos != -1) { levelLabel.Text = pos.ToString(); if(pos<activeHistogram.Values.Length) countLabel.Text = activeHistogram.Values[pos].ToString(); percentileLabel.Text = ((float)activeHistogram.Values[pos] * 100 / stat.PixelsCount).ToString("F2"); } else { levelLabel.Text = ""; countLabel.Text = ""; percentileLabel.Text = ""; } } // Selection changed in the histogram private void histogram_SelectionChanged(object sender, HistogramEventArgs e) { int min = e.Min; int max = e.Max; int count = 0; levelLabel.Text = min.ToString() + "..." + max.ToString(); // count pixels for (int i = min; i <= max; i++) { count += activeHistogram.Values[i]; } countLabel.Text = count.ToString(); percentileLabel.Text = ((float)count * 100 / stat.PixelsCount).ToString("F2"); } // On "Log" check - switch mode private void logCheck_CheckedChanged(object sender, System.EventArgs e) { } private void histogram_MouseEnter(object sender, EventArgs e) { mouseOverInfoLbl.Visible = false; } private void histogram_MouseLeave(object sender, EventArgs e) { mouseOverInfoLbl.Visible = true; } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732495795 25/11/2024 01:49:55 |
| _ | histogram | 0 octets | 1541007196 31/10/2018 18:33:16 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-photobrol-source-rf-view/controls/HistogramUserControl.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.