// On selection changed private void document_SelectionChanged(object sender, SelectionEventArgs e) { this.PositionToolStripStatusLabel.Text = string.Format("({0}, {1}) - {2} x {3}", e.Location.X, e.Location.Y, e.Size.Width, e.Size.Height); }
// On mouse position over image changed private void document_MouseImagePosition(object sender, SelectionEventArgs e) { if (e.Location.X >= 0) { this.PositionToolStripStatusLabel.Text = string.Format(" ({0}, {1})", e.Location.X, e.Location.Y); // get current color Bitmap image = ((ImageHandlerForm)sender).Image; if (image.PixelFormat == PixelFormat.Format24bppRgb) { Color color = image.GetPixel(e.Location.X, e.Location.Y); RGB rgb = new RGB(color); YCbCr ycbcr = new YCbCr(); AForge.Imaging.ColorConverter.RGB2YCbCr(rgb, ycbcr); // RGB this.colorPanel.Text = string.Format("RGB: {0}, {1}, {2}", color.R, color.G, color.B); // HSL this.hslPanel.Text = string.Format("HSL: {0}, {1:F3}, {2:F3}", (int)color.GetHue(), color.GetSaturation(), color.GetBrightness()); // YCbCr this.ycbcrPanel.Text = string.Format("YCbCr: {0:F3}, {1:F3}, {2:F3}", ycbcr.Y, ycbcr.Cb, ycbcr.Cr); } else if (image.PixelFormat == PixelFormat.Format8bppIndexed) { Color color = image.GetPixel(e.Location.X, e.Location.Y); this.colorPanel.Text = "Gray: " + color.R.ToString(); this.hslPanel.Text = ""; this.ycbcrPanel.Text = ""; } } else { this.PositionToolStripStatusLabel.Text = ""; this.colorPanel.Text = ""; this.hslPanel.Text = ""; this.ycbcrPanel.Text = ""; } }