private void DrawHistogram(object sender = null, EventArgs e = null) { HistogramImage.Image.Dispose(); HistogramImage.Image = new Bitmap(HistogramImage.Width, HistogramImage.Height); Graphics gr = Graphics.FromImage(HistogramImage.Image); Pen Pen_R = new Pen(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), x_scale); Pen Pen_G = new Pen(new SolidBrush(Color.FromArgb(100, 0, 255, 0)), x_scale); Pen Pen_B = new Pen(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), x_scale); Pen Pen_Grey = new Pen(new SolidBrush(Color.FromArgb(100, 150, 150, 150)), x_scale); Brush red_brush = new SolidBrush(Color.FromArgb(100, 200, 0, 0)); Pen red = new Pen(red_brush); gr.DrawLine(red, 5, HistogramImage.Height - 9, HistogramImage.Width - 5, HistogramImage.Height - 9); gr.DrawString("0", new Font("Arial", 7), red_brush, new PointF(1.0F, hHeight - 10)); gr.DrawString("255", new Font("Arial", 7), red_brush, new PointF(hWidth - 17, hHeight - 10)); gr.DrawLine(red, 5, HistogramImage.Height - 9, HistogramImage.Width - 5, HistogramImage.Height - 9); gr.DrawString("0", new Font("Arial", 7), red_brush, new PointF(1.0F, hHeight - 10)); gr.DrawString("255", new Font("Arial", 7), red_brush, new PointF(hWidth - 17, hHeight - 10)); int val = int.Parse(Level.Text); for (int i = 0; i < 256; i++) { if (Reverse.Checked) { if (i < val) { gr.DrawLine(new Pen(Color.FromArgb(100, 150, 150, 150)), i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[3, i] * y_scale))); } else { gr.DrawLine(new Pen(Color.OrangeRed), i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[3, i] * y_scale))); } } else { if (i <= val) { gr.DrawLine(new Pen(Color.OrangeRed), i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[3, i] * y_scale))); } else { gr.DrawLine(new Pen(Color.FromArgb(100, 150, 150, 150)), i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[3, i] * y_scale))); } } } iw.setBitmap(prevImg); iw.Treshold(val, Reverse.Checked); HistogramImage.Invalidate(); gr.Dispose(); }
private void DrawHistogram(object sender = null, EventArgs e = null) { HistogramImage.Image.Dispose(); HistogramImage.Image = new Bitmap(HistogramImage.Width, HistogramImage.Height); Graphics gr = Graphics.FromImage(HistogramImage.Image); Pen Pen_R = new Pen(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), x_scale); Pen Pen_G = new Pen(new SolidBrush(Color.FromArgb(100, 0, 255, 0)), x_scale); Pen Pen_B = new Pen(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), x_scale); Pen Pen_Grey = new Pen(new SolidBrush(Color.FromArgb(100, 150, 150, 150)), x_scale); Brush red_brush = new SolidBrush(Color.FromArgb(100, 200, 0, 0)); Pen red = new Pen(red_brush); gr.DrawLine(red, 5, HistogramImage.Height - 9, HistogramImage.Width - 5, HistogramImage.Height - 9); gr.DrawString("0", new Font("Arial", 7), red_brush, new PointF(1.0F, hHeight - 10)); gr.DrawString("255", new Font("Arial", 7), red_brush, new PointF(hWidth - 17, hHeight - 10)); gr.DrawLine(red, 5, HistogramImage.Height - 9, HistogramImage.Width - 5, HistogramImage.Height - 9); gr.DrawString("0", new Font("Arial", 7), red_brush, new PointF(1.0F, hHeight - 10)); gr.DrawString("255", new Font("Arial", 7), red_brush, new PointF(hWidth - 17, hHeight - 10)); for (int i = 0; i < 256; i++) { if (checkRed.Checked) { gr.DrawLine(Pen_R, i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[0, i] * y_scale))); } if (checkGreen.Checked) { gr.DrawLine(Pen_G, i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[1, i] * y_scale))); } if (checkBlue.Checked) { gr.DrawLine(Pen_B, i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[2, i] * y_scale))); } gr.DrawLine(Pen_Grey, i * x_scale + 5, hHeight - 10, i * x_scale + 5, (float)(hHeight - 10 - (float)((float)LUT[3, i] * y_scale))); } image.Dispose(); image = new Bitmap(HistogramImage.Image); HistogramImage.Invalidate(); gr.Dispose(); }