public static void DrawToGraphics(ref Image i, Beads b, bool original, bool drawgrid, Color? TransparentColourOverload = null) { const int pixelsize = 10; int w = b.width * pixelsize; int h = b.height * pixelsize; int cx = 0; int cy = 0; Brush brush = new SolidBrush(Color.White); i = new Bitmap(w, h); Graphics graphics = Graphics.FromImage(i); //clear graphics.FillRectangle(brush, 0, 0, w, h); b.Grid = new List<Tuple<Tuple<int, int>, Rectangle>>(); //draw imagae for (int y = 0; y < b.height; y++) { for (int x = 0; x < b.width; x++) { var c = b.GetPixelColour(x, y, original); if (TransparentColourOverload != null && c.Equals(Color.Transparent)) c = (Color)TransparentColourOverload; brush = new SolidBrush(c); var r = new Rectangle(cx * pixelsize, cy * pixelsize, pixelsize, pixelsize); b.Grid.Add(new Tuple<Tuple<int, int>, Rectangle>(new Tuple<int, int>(x, y), r)); graphics.FillRectangle(brush, r); if ((x + 1) == b.width) { cx = 0; cy++; } else { cx++; } } } //overlay if (drawgrid) { var pen = new Pen(Color.White); for (int x = 0; x < b.width; x++) { graphics.DrawLine(pen, x * pixelsize, 0, x * pixelsize, h); } for (int y = 0; y < b.height; y++) { graphics.DrawLine(pen, 0, y * pixelsize, w, y * pixelsize); } } }
public static int GetUniqueCount(Beads b, bool original) { var seen = new List<Color>(); var l = new object(); Parallel.For(0, b.height, (y) => { for (int x = 0; x < b.width; x++) { var c = b.GetPixelColour(x, y, original); if (seen.Contains(c) == false) { lock (l) { seen.Add(c); } } } }); return seen.Count; }
public static void SetColourText(Beads b, ToolStripStatusLabel ts, bool orig, int x, int y) { var c = b.GetPixelColour(x, y, orig); ts.Text = GetColourDescription(c, orig); ts.BackColor = c; ts.ForeColor = ColorExtras.GetNegativeColour(c); }