// On mouse position over image changed private void document_MouseImagePosition(object sender, SelectionEventArgs e) { if (e.Location.X >= 0) { this.selectionPanel.Text = string.Format( "({0}, {1})", e.Location.X, e.Location.Y ); // get current color Bitmap image = ((ImageDoc) 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 ); //SS: отображение области для расчета среднего значения цвета Rectangle avArea=((ImageDoc)sender).AverageArea; if (!avArea.IsEmpty) this.avColorPanel.Text = string.Format("AVERAGE: [{0}; {1}] - [{2}; {3}]", avArea.Left, avArea.Top, avArea.Right, avArea.Bottom); else this.avColorPanel.Text = ""; if (((ImageDoc)sender).SelectingArea) this.infoPanel.Text = "Now select area or press right mouse button to cancel"; else if (((ImageDoc)sender).SelectingPoint || ((ImageDoc)sender).SelectingLayerPoint) this.infoPanel.Text = "Now pick a point or press right mouse button to cancel"; else this.infoPanel.Text = ""; } 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.selectionPanel.Text = ""; this.colorPanel.Text = ""; this.hslPanel.Text = ""; this.ycbcrPanel.Text = ""; } }
// On selection changed private void document_SelectionChanged(object sender, SelectionEventArgs e) { this.selectionPanel.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.selectionPanel.Text = string.Format( "({0}, {1})", e.Location.X, e.Location.Y ); // get current color Bitmap image = ((ImageDoc) sender).Image; if (image.PixelFormat == PixelFormat.Format24bppRgb) { Color color = image.GetPixel(e.Location.X, e.Location.Y); RGB rgb = new RGB( color ); YCbCr ycbcr = AForge.Imaging.YCbCr.FromRGB( rgb ); // 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.selectionPanel.Text = ""; this.colorPanel.Text = ""; this.hslPanel.Text = ""; this.ycbcrPanel.Text = ""; } }