Click here to Skip to main content
12,634,888 members (28,941 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
please help me to process it more faster..
here's my code..
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 23-Jan-13 2:59am
Updated 23-Jan-13 3:38am
CHill60159.4K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You're not setting IsColorFound when you find the colour so the outer loop never breaks
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

You might seek for a C++ solution?
Cheers
Andi
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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:


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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

bmp1 = picturebox2...tnx
Godbless :)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100