private void cmdVerify_Click(object sender, EventArgs e) { string retval = ","; //Prepare return value long cRaw = Countword(tCols.Text, "\r\n"); //Count ubound of raw-array string[] aryTmp, Raw = aSplit(tCols.Text, "\r\n"); //Define and assign raw-array long[] aryColor = new long[cRaw + 1], aryMtch = new long[cRaw + 1], //Define holders of long values aryMinV = new long[cRaw + 1], aryMaxV = new long[cRaw + 1], aryThr = new long[cRaw + 1]; Color thisCol, findCol; //Define holders of temp. colors for (int a = 0; a <= cRaw; a++) //Loop to parse raw-array { aryTmp = aSplit(Raw[a], "p"); //Split raw-array %a aryColor[a] = Convert.ToInt32(aryTmp[0]); //Assign target color of %a aryMinV[a] = Convert.ToInt32(aryTmp[1]); //Assign minimum value of %a aryMaxV[a] = Convert.ToInt32(aryTmp[2]); //Assign maximum value of %a aryThr[a] = Convert.ToInt32(aryTmp[3]); //Assign color threshold of %a } pBox.Load(imgPath); Application.DoEvents(); //Load picture to picturebox Image.FastBitmap img = new Image.FastBitmap(pBox.Image as Bitmap); //Load picture as FastBitmap for (int X = 0; X < 90; X++) //Start X loop { for (int Y = 0; Y < 65; Y++) //Start Y loop { thisCol = img.GetPixel(X, Y); //Read color of current pixel for (int a = 0; a <= cRaw; a++) //Scan for supplied targets { findCol = Long2Col(aryColor[a]); //Convert target color from long if (CompareColors(thisCol, findCol, aryThr[a])) //If colors match, add +1 found { aryMtch[a]++; //Add +1 to found pixels } } } } for (int a = 0; a <= cRaw; a++) //Loop to sum up results { MessageBox.Show("Total found on col #" + a + ": " + aryMtch[a]); // *debug* Display matchcount if (aryMtch[a] >= aryMinV[a] && aryMtch[a] <= aryMaxV[a]) //If correct number of matches { retval += Convert.ToString(a) + ","; //Add target-ID to result list } } MessageBox.Show("Found colors: " + retval); // *debug* Display retval }
private void pBox_MouseUp(object sender, MouseEventArgs e) { long Matches = 0; //Define value to hold matchcount pBox.Load(imgPath); Application.DoEvents(); //Load picture to picturebox bool[,] matches = new bool[90, 65]; //Define 2d array to hold results Color col = (pBox.Image as Bitmap).GetPixel(e.X, e.Y); //Get color of the pixel clicked Image.FastBitmap img = new Image.FastBitmap(pBox.Image as Bitmap); //Load picture as FastBitmap for (int y = 0; y < 65; y++) //Start Y-loop { for (int x = 0; x < 90; x++) //Start X-loop { Color tcol = img.GetPixel(x, y); //Get current color if (CompareColors(tcol, col, 20)) //If current and selected match { Matches++; //Increase match count matches[x, y] = true; //Indicate a match } else //else... { matches[x, y] = false; //Indicate a mismatch } } } img.Release(); //Dispose of the FastBitmap Image.FastBitmap rmg = new Image.FastBitmap(pBox.Image as Bitmap); //Load picture as FastBitmap for (int y = 0; y < 65; y++) //Start comparative Y-loop { for (int x = 0; x < 90; x++) //Start comparative X-loop { if (matches[x, y]) //If there's a stored match { rmg.SetPixel(x, y, Color.White); //Indicate with a white spot } } } rmg.Release(); //Dispose of the FastBitmap pBox.Refresh(); //Force the box to refresh image MessageBox.Show(Matches + "\r\n" + Col2Long(col)); //Display results of scan Clipboard.SetText(Col2Long(col) + "-" + //Clipboard results of scan (Matches - 20) + "-" + (Matches + 20) + "-20"); }
private void cmdIdent_Click(object sender, EventArgs e) { long Tick01 = Tick(); // *debug* performance timer Color[,] col = new Color[90, 65]; //Define color array (speedh4x) bool[,] matches = new bool[90, 65]; //Define bool array for matches pBox.Load(imgPath); Application.DoEvents(); //Load picture to picturebox Image.FastBitmap img = new Image.FastBitmap(pBox.Image as Bitmap); //Load picture as FastBitmap long Tick02 = Tick(); // *debug* performance timer for (int y = 0; y < 65; y++) //Start first Y-loop { for (int x = 0; x < 90; x++) //Start first X-loop { col[x, y] = img.GetPixel(x, y); //Get pixelcolor to color array } } Color MaxCol = Color.Black; long CurNum, MaxNum = 0; //Define initial values for (int cY = 0; cY < 65; cY++) //Start main Y-loop { for (int cX = 0; cX < 65; cX++) //Start main X-loop { CurNum = 0; //Reset current matches to zero for (int Y = 0; Y < 65; Y++) //Start comparative Y-loop { for (int X = 0; X < 90; X++) //Start comparative X-loop { if (CompareColors(col[X, Y], col[cX, cY], 10)) //If match { CurNum++; //Increase matches matches[X, Y] = true; //Add match to bool array } else //else... { matches[X, Y] = false; //Add mismatch to bool array } } } if (CurNum > MaxNum) //If this scan exceeds record { MaxNum = CurNum; MaxCol = col[cX, cY]; //Set new record count and color this.Text = MaxNum + " / " + Col2Long(MaxCol); // *debug* display record values this.BackColor = MaxCol; // *debug* set form background } } } img.Release(); //Dispose the FastBitmap long Tick03 = Tick(); // *debug* performance timer //// From here on, (improved) code from KeyUp sub //// Image.FastBitmap rmg = new Image.FastBitmap(pBox.Image as Bitmap); //Load picture as FastBitmap for (int y = 0; y < 65; y++) //Start comparative Y-loop { for (int x = 0; x < 90; x++) //Start comparative X-loop { if (matches[x, y]) //If there's a stored match { rmg.SetPixel(x, y, Color.White); //Indicate with a white spot } else //else... { rmg.SetPixel(x, y, Color.Black); //Indicate with a black spot } } } rmg.Release(); //Dispose of the FastBitmap pBox.Refresh(); //Force the box to refresh image MessageBox.Show("" + (Tick02 - Tick01) + "\n" + (Tick03 - Tick02) + "\n" + (Tick() - Tick03)); // *debug* display timer result }