Search code examples
iphone

Detecting bright/dark points on iPhone screen


I would like to detect and mark the brightest and the darkest spot on an image.

For example I am creating an AVCaptureSession and showing the video frames on screen using AVCaptureVideoPreviewLayer. Now on this camera output view I would like to be able to mark the current darkest and lightest points.

An Example

Would i have to read Image pixel data? If so, how can i do that?


Solution

  • In any case, you must to read pixels to detect this. But if you whant to make it fast, dont read EVERY pixel: read only 1 of 100:

    for (int x = 0; x < widgh-10; x+=10) {
       for (int y = 0; y < height-10; y+=10) {
          //Detect bright/dark points here
       }
    } 
    

    Then, you may read pixels around the ones you find, to make results more correct


    Here is the way to get pixel data: stackoverflow.com/questions/448125/ at the most bright point, red+green+blue must be maximum (225+225+225 = 675 = 100% white). At the most dark point red+green+blue must bo minimum (0 = 100% black).