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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using be.gaudry.photobrol.model.image;
  9. using be.gaudry.photobrol.view.controls.histogram;
  10. using be.gaudry.model.config;
  11.  
  12. namespace be.gaudry.photobrol.view.controls
  13. {
  14. public partial class HistogramUserControl : UserControl
  15. {
  16. private int currentImageHash = 0;
  17. private static Color[] colors;
  18. private ImageStatistics stat;
  19. private be.gaudry.model.math.Histogram activeHistogram;
  20.  
  21. public HistogramUserControl()
  22. {
  23. colors = new Color[] {
  24. Color.FromArgb(192, 0, 0),
  25. Color.FromArgb(0, 192, 0),
  26. Color.FromArgb(0, 0, 192),
  27. Color.FromArgb(128, 128, 128),
  28. };
  29. activeHistogram = null;
  30. InitializeComponent();
  31. SourcesManager.addSource(new Source(
  32. "Histogrammes",
  33. this.Name,
  34. "http://www.cst.fr/IMG/pdf/Les_mesures_sur_les_images_numeriques.pdf",
  35. "Informations sur les histogrammes"
  36. )
  37. );
  38.  
  39. }
  40.  
  41.  
  42. // Gather image statistics
  43. public void GatherStatistics(Bitmap image)
  44. {
  45. // avoid calculation in the case of the same image
  46. if (image != null)
  47. {
  48. if (currentImageHash == image.GetHashCode())
  49. return;
  50. currentImageHash = image.GetHashCode();
  51. }
  52.  
  53. if (image != null)
  54. System.Diagnostics.Debug.WriteLine("=== Gathering histogram");
  55.  
  56. // busy
  57. Capture = true;
  58. Cursor = Cursors.WaitCursor;
  59.  
  60. // get statistics
  61. stat = (image == null) ? null : new ImageStatistics(image);
  62.  
  63. // free
  64. Cursor = Cursors.Arrow;
  65. Capture = false;
  66.  
  67. // clean combo
  68. channelCombo.Items.Clear();
  69. channelCombo.Enabled = false;
  70.  
  71. if (stat != null)
  72. {
  73. if (!stat.IsGrayscale)
  74. {
  75. // RGB picture
  76. channelCombo.Items.AddRange(new object[] { "Rouge", "Vert", "Bleu" });
  77. channelCombo.Enabled = true;
  78. }
  79. else
  80. {
  81. // grayscale picture
  82. channelCombo.Items.Add("Gris");
  83. }
  84. channelCombo.SelectedIndex = 0;
  85. }
  86. else
  87. {
  88. histogram.Values = null;
  89. meanLabel.Text = String.Empty;
  90. stdDevLabel.Text = String.Empty;
  91. medianLabel.Text = String.Empty;
  92. minLabel.Text = String.Empty;
  93. maxLabel.Text = String.Empty;
  94. levelLabel.Text = String.Empty;
  95. countLabel.Text = String.Empty;
  96. percentileLabel.Text = String.Empty;
  97. }
  98. }
  99.  
  100. // selection changed in channels combo
  101. private void channelCombo_SelectedIndexChanged(object sender, System.EventArgs e)
  102. {
  103. if (stat != null)
  104. {
  105. SwitchChannel((stat.IsGrayscale) ? 3 : channelCombo.SelectedIndex);
  106. }
  107. }
  108.  
  109. // Switch channel
  110. public void SwitchChannel(int channel)
  111. {
  112. if ((channel >= 0) && (channel <= 2))
  113. {
  114. if (!stat.IsGrayscale)
  115. {
  116. histogram.Color = colors[channel];
  117. activeHistogram = (channel == 0) ? stat.Red : (channel == 1) ? stat.Green : stat.Blue;
  118. }
  119. }
  120. else if (channel == 3)
  121. {
  122. if (stat.IsGrayscale)
  123. {
  124. histogram.Color = colors[3];
  125. activeHistogram = stat.Gray;
  126. }
  127. }
  128.  
  129. if (activeHistogram != null)
  130. {
  131. histogram.Values = activeHistogram.Values;
  132.  
  133. meanLabel.Text = activeHistogram.Mean.ToString("F2");
  134. stdDevLabel.Text = activeHistogram.StdDev.ToString("F2");
  135. medianLabel.Text = activeHistogram.Median.ToString();
  136. minLabel.Text = activeHistogram.Min.ToString();
  137. maxLabel.Text = activeHistogram.Max.ToString();
  138. }
  139. }
  140.  
  141. // Cursor position changed over the histogram
  142. private void histogram_PositionChanged(object sender, HistogramEventArgs e)
  143. {
  144. int pos = e.Position;
  145.  
  146. if (pos != -1)
  147. {
  148.  
  149. levelLabel.Text = pos.ToString();
  150. if(pos<activeHistogram.Values.Length) countLabel.Text = activeHistogram.Values[pos].ToString();
  151. percentileLabel.Text = ((float)activeHistogram.Values[pos] * 100 / stat.PixelsCount).ToString("F2");
  152. }
  153. else
  154. {
  155.  
  156. levelLabel.Text = "";
  157. countLabel.Text = "";
  158. percentileLabel.Text = "";
  159. }
  160. }
  161.  
  162. // Selection changed in the histogram
  163. private void histogram_SelectionChanged(object sender, HistogramEventArgs e)
  164. {
  165. int min = e.Min;
  166. int max = e.Max;
  167. int count = 0;
  168.  
  169. levelLabel.Text = min.ToString() + "..." + max.ToString();
  170.  
  171. // count pixels
  172. for (int i = min; i <= max; i++)
  173. {
  174. count += activeHistogram.Values[i];
  175. }
  176. countLabel.Text = count.ToString();
  177. percentileLabel.Text = ((float)count * 100 / stat.PixelsCount).ToString("F2");
  178. }
  179.  
  180. // On "Log" check - switch mode
  181. private void logCheck_CheckedChanged(object sender, System.EventArgs e)
  182. {
  183. histogram.LogView = logCheck.Checked;
  184. }
  185.  
  186. private void histogram_MouseEnter(object sender, EventArgs e)
  187. {
  188. mouseOverInfoLbl.Visible = false;
  189. }
  190.  
  191. private void histogram_MouseLeave(object sender, EventArgs e)
  192. {
  193. mouseOverInfoLbl.Visible = true;
  194. }
  195. }
  196. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/view/controls/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1717205171 01/06/2024 03:26:11
| _histogram0 octets1541007196 31/10/2018 18:33:16
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csRGBLHistogramUserControl.cs7.13 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csHistogramUserControl.Designer.cs15.78 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csCompressJpegUserControl.Designer.cs13.8 Ko31/10/2018 18:32:51-refusé-
Afficher le fichier .resx|.resxCompressJpegUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxRGBLHistogramUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csHistogramUserControl.cs6.31 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxHistogramUserControl.resx5.68 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csCompressJpegUserControl.cs3.77 Ko31/10/2018 18:32:51-refusé-
Afficher le fichier .cs|.csRGBLHistogramUserControl.Designer.cs29.94 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csImageEditorUserControl.cs41.8 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .resx|.resxImageEditorUserControl.resx17.34 Ko31/10/2018 18:32:52-refusé-
Afficher le fichier .cs|.csImageEditorUserControl.Designer.cs126.15 Ko31/10/2018 18:32:52-refusé-

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.

Document créé le 30/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-photobrol-source-rf-view/controls//HistogramUserControl.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.