/// <summary> /// Gets a bitmap with the RGB histograms /// </summary> /// <returns>Three histograms for R, G and B values in the Histogram</returns> public Bitmap Visualize() { int oneColorHeight = 100; int margin = 10; float[] maxValues = new float[] { Red.Max(), Green.Max(), Blue.Max() }; byte[][] values = new byte[][] { Red, Green, Blue }; Bitmap histogramBitmap = new Bitmap(276, oneColorHeight * 3 + margin * 4); Graphics g = Graphics.FromImage(histogramBitmap); g.FillRectangle(Brushes.White, 0, 0, histogramBitmap.Width, histogramBitmap.Height); int yOffset = margin + oneColorHeight; for (int i = 0; i < 256; i++) { for (int color = 0; color < 3; color++) { g.DrawLine(p[color], margin + i, yOffset * (color + 1), margin + i, yOffset * (color + 1) - (values[color][i] / maxValues[color]) * oneColorHeight); } } for (int i = 0; i < 3; i++) { g.DrawString(p[i].Color.ToKnownColor() + ", max value: " + maxValues[i], SystemFonts.SmallCaptionFont, Brushes.Silver, margin + 11, yOffset * i + margin + margin + 1); g.DrawString(p[i].Color.ToKnownColor() + ", max value: " + maxValues[i], SystemFonts.SmallCaptionFont, Brushes.Black, margin + 10, yOffset * i + margin + margin); g.DrawRectangle(p[i], margin, yOffset * i + margin, 256, oneColorHeight); } g.Dispose(); return(histogramBitmap); }
/// <summary> /// Gets a bitmap with the RGB histograms /// </summary> /// <returns>Three histograms for R, G and B values in the Histogram</returns> public Image <Rgba32> Visualize() { int oneColorHeight = 100; int margin = 10; float[] maxValues = new float[] { Red.Max(), Green.Max(), Blue.Max() }; byte[][] values = new byte[][] { Red, Green, Blue }; Image <Rgba32> histogramBitmap = new Image <Rgba32>(276, oneColorHeight * 3 + margin * 4); ///Graphics g = Graphics.FromImage(histogramBitmap); var rect = new RectangleF(0, 0, histogramBitmap.Width, histogramBitmap.Height); histogramBitmap.Mutate(ctx => ctx.Fill(Rgba32.White, rect)); int yOffset = margin + oneColorHeight; for (int i = 0; i < 256; i++) { for (int color = 0; color < 3; color++) { PointF[] points = { new PointF(margin + i, yOffset * (color + 1)), new PointF(margin + i, yOffset * (color + 1) - (values[color][i] / maxValues[color]) * oneColorHeight) }; histogramBitmap.Mutate(ctx => ctx.DrawLines(p[color], points)); } } for (int i = 0; i < 3; i++) { var point = new PointF(margin + 11, yOffset * i + margin + margin + 1); histogramBitmap.Mutate(ctx => ctx.DrawText(penNames[i] + ", max value: " + maxValues[i], smallCaptionFont, Rgba32.Silver, point)); point = new PointF(margin + 10, yOffset * i + margin + margin); histogramBitmap.Mutate(ctx => ctx.DrawText(penNames[i] + ", max value: " + maxValues[i], smallCaptionFont, Rgba32.Black, point)); rect = new RectangleF(margin, yOffset * i + margin, 256, oneColorHeight); histogramBitmap.Mutate(ctx => ctx.Draw(p[i], rect)); } return(histogramBitmap); }