Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
please help me to process it more faster..
here's my code..
C#
int height = pictureBox1.Image.Height;
int width = pictureBox1.Image.Width;

for (int i = 0; i < height; i++)
{

    for (int j = 0; j < width; j++)
    {

         if ((bmp.GetPixel(j, i) == bmp1.GetPixel(22, 16))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(50, 17))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(89, 16))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(116, 18))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(157, 21))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(185, 17))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(216, 17))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(258, 16))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(289, 19))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(23, 54))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(51, 52))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(85, 51))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(126, 48))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(159, 51))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(191, 52))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(223, 50))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(259, 50))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(288, 49))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(26, 82))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(56, 82))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(89, 85))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(125, 85))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(154, 82))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(186, 85))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(214, 83))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(248, 83))
             || (bmp.GetPixel(j, i) == bmp1.GetPixel(285, 81)))
        {
             MessageBox.Show("color found");
             break;
        }
                          
    }
                       if (IsColorFound == true)
                       {
                           break;
                       }
                   }

                   if (IsColorFound == false)
                   {
                       listBox1.Items.Add("None");
                       // MessageBox.Show("No color found.");
                   }

               }
               else
               {
                   MessageBox.Show("Image is not loaded");
               }
Posted
Updated 23-Jan-13 2:38am
v2

You're not setting IsColorFound when you find the colour so the outer loop never breaks
 
Share this answer
 
HTe problem is that you're using GetPixel, which is extremely slow. I suggest searching the articles for a series of them written by Christian Graus, "Image processing for dummies". They'll show you a MUCH faster way of looking at individual pixels.
 
Share this answer
 
You might seek for a C++ solution?
Cheers
Andi
 
Share this answer
 
You are calling GetPixel way too many times, as others have pointed out.

Instead of calling it twice on every line of your IF statement, try:

C#
for (int i = 0; i < height; i++)
{

    for (int j = 0; j < width; j++)
    {

         Color x = bmp.GetPixel(j, i);         // get it once and store it here

         if ((x == bmp1.GetPixel(22, 16))
             || (x == bmp1.GetPixel(50, 17))
             || (x == bmp1.GetPixel(89, 16))
             || (x == bmp1.GetPixel(116, 18))
             || (x == bmp1.GetPixel(157, 21))

         ...etc

        {
             MessageBox.Show("color found");
             break;
        }
                          
    }


..which will improve it significantly.
 
Share this answer
 
bmp1 = picturebox2...tnx
Godbless :)
 
Share this answer
 
Comments
CHill60 23-Jan-13 8:32am    
Why have you answered your own question? I'm not even sure I understand the solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900