Histogram.cs
Description du code
Histogram.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# (Histogram.cs) (307 lignes)
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; namespace be.gaudry.photobrol.view.controls.histogram { public class Histogram : Control { #region declarations and constructors private Color color; private int width; private int height; private bool log; private int[] values; private int max; private double maxLog; private bool allowSelection; private Pen blackPen; private Pen whitePen; private Pen drawPen; private bool tracking; private bool over; private int start, stop; // events public delegate void HistogramEventHandler(object sender, HistogramEventArgs e); public event HistogramEventHandler PositionChanged; public event HistogramEventHandler SelectionChanged; public Histogram() { color = Color.Black; width = 256; height = 150; log = true; tracking = false; over = false; InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); } #endregion #region properties // Color property public Color Color { get { return color; } set { color = value; drawPen.Dispose(); Invalidate(); } } // Width property [DefaultValue(256)] public int HistogramWidth { get { return width; } set { width = value; Invalidate(); } } // Height property [DefaultValue(150)] public int HistogramHeight { get { return height; } set { height = value; Invalidate(); } } // Allow selection property [DefaultValue(false)] public bool AllowSelection { get { return allowSelection; } set { allowSelection = value; } } // LogView property [DefaultValue(false)] public bool LogView { get { return log; } set { log = value; Invalidate(); } } // Values property [Browsable(false)] public int[] Values { set { values = value; if (values != null) { // get the max max = 0; foreach (int v in values) { if (v > max) { max = v; maxLog = Math.Log10(max); } } } Invalidate(); } } #endregion // Dispose protected override void Dispose( bool disposing ) { if ( disposing ) { blackPen.Dispose( ); whitePen.Dispose( ); drawPen.Dispose( ); } base.Dispose( disposing ); } // Init component private void InitializeComponent( ) { // // Histogram // } // Paint control protected override void OnPaint( PaintEventArgs pe ) { Graphics g = pe.Graphics; int x = ( ClientRectangle.Right - width ) / 2; int y = 5; int l; // draw rectangle around the image g.DrawRectangle( blackPen, x - 1, y - 1, width + 1, height + 1 ); if ( values != null ) { int count = Math.Min( values.Length, width ); int start = Math.Min( this.start, this.stop ); int stop = Math.Max( this.start, this.stop ); if ( tracking ) { // fill region of selection g.FillRectangle( brush, x + start, y, Math.Abs( start - stop ), height ); brush.Dispose( ); } // draw histogram for ( int i = 0; i < count; i++ ) { if ( log ) { l = ( values[i] == 0 ) ? 0 : (int) ( Math.Log10( values[i] ) * height / maxLog ); } else { l = (int) ( values[i] * height / max ); } if ( l != 0 ) { g.DrawLine( ( ( tracking ) && ( i >= start ) && ( i <= stop ) ) ? whitePen : drawPen, ); } } } // Calling the base class OnPaint base.OnPaint( pe ); } // On mouse down private void Histogram_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e ) { if ( ( allowSelection ) && ( values != null ) ) { int x = ( ClientRectangle.Right - width ) / 2; int y = 5; if ( ( e.X >= x ) && ( e.Y >= y ) && ( e.X < x + width ) && ( e.Y < y + height ) ) { // start selection tracking = true; start = e.X - x; this.Capture = true; } } } // On mouse up private void Histogram_MouseUp( object sender, System.Windows.Forms.MouseEventArgs e ) { if ( tracking ) { // stop selection tracking = false; this.Capture = false; Invalidate( ); } } // On mouse move private void Histogram_MouseMove( object sender, System.Windows.Forms.MouseEventArgs e ) { if ( ( allowSelection ) && ( values != null ) ) { int x = ( ClientRectangle.Right - width ) / 2; int y = 5; if ( !tracking ) { if ( ( e.X >= x ) && ( e.Y >= y ) && ( e.X < x + width ) && ( e.Y < y + height ) ) { over = true; // moving over this.Cursor = Cursors.Cross; // notify parent if ( PositionChanged != null ) } else { this.Cursor = Cursors.Default; if ( over ) { over = false; // notify parent if ( PositionChanged != null ) } } } else { // selecting region stop = e.X - x; stop = Math.Min( stop, 255 ); stop = Math.Max( stop, 0 ); Invalidate( ); // notify parent if ( SelectionChanged != null ) SelectionChanged( this, new HistogramEventArgs( Math.Min( start, stop ), Math.Max( start, stop ) ) ); } } } // On mouse leave private void Histogram_MouseLeave( object sender, System.EventArgs e ) { if ( ( allowSelection ) && ( values != null ) && ( !tracking ) ) { // notify parent if ( PositionChanged != null ) } } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732300941 22/11/2024 19:42:21 |
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/histogram//Histogram.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.