title: Detect black pixel in image iOS
body: <p>As of now I am searching every pixel 1 by 1 checking the color and seeing if it's black... if it isn't I move on to the next pixel. This is taking forever as I can only check approx. 100 pixels per second (speeding up my NSTimer freezes the app because it can't check fast enough.) So is there anyway I can just have Xcode return all the pixels that are black and ignore everything else so I only have to check those pixels and not every pixel. I am trying to detect a black pixel furthest to the left on my image. </p>
  
  <p>Here is my current code.</p>
  
  <pre><code>- (void)viewDidLoad {
      timer = [NSTimer scheduledTimerWithTimeInterval: 0.01
                                               target: self
                                             selector:@selector(onTick:)
                                             userInfo: nil repeats:YES];
      y1 = 0;
      x1 = 0;
      initialImage = 0;
      height1 = 0;
      width1 = 0;
  }
  
  -(void)onTick:(NSTimer *)timer {
      if (initialImage != 1) {
          /*
          IMAGE INITIALLY GETS SET HERE... "image2.image = [blah blah blah];" took this out for non disclosure reasons
          */
          initialImage = 1;
      }
      //image2 is the image I'm checking the pixels of.
      width1 = (int)image2.size.width;
      height1 = (int)image2.size.height;
      CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(image2.CGImage));
      const UInt32 *pixels = (const UInt32*)CFDataGetBytePtr(imageData);
      if ( (pixels[(x1+(y1*width1))]) == 0x000000) { //0x000000 is black right?
          NSLog(@"black!");
          NSLog(@"x = %i", x1);
          NSLog(@"y = %i", y1);
      }else {
          NSLog(@"val: %lu", (pixels[(x1+(y1*width1))]));
          NSLog(@"x = %i", x1);
          NSLog(@"y = %i", y1);
          x1 ++;
          if (x1 &gt;= width1) {
              y1 ++;
              x1 = 0;
          }
      }
      if (y1 &gt; height1) {
          /*
          MY UPDATE IMAGE CODE GOES HERE (IMAGE CHANGES EVERY TIME ALL PIXELS HAVE BEEN CHECKED
          */
          y1 = 0;
          x1 = 0;
      }
  </code></pre>
  
  <p>Also what if a pixel is really close to black but not perfectly black... Can I add a margin of error in there somewhere so it will still detect pixels that are like 95% black? Thanks!</p>