0

I need to detect the predominant color or the ligthing of a picture. It is possible? And how?

It is possibile to extract that data from a CGIMAGE? Thanks

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
JosephITA
  • 502
  • 2
  • 11
  • 21

1 Answers1

0

Resize the image to 1x1 pixel. Use the category UIImage+ColorAtPixel.h to extract the value of the pixel. You can transform the CGImage to a UIImage with imageWithCGImage:.

To extract the value of the pixel, the category creates a context (CGBitmapContextCreate) with a RGBA buffer of 4 char and draws the image there. Then it extracts the color from the 4 components (RGBA) of the image.

Jano
  • 62,815
  • 21
  • 164
  • 192
  • There are many around. For example, scale to 1x1 using http://stackoverflow.com/a/2658801/412916 and then get the color at 0,0 with http://stackoverflow.com/a/1262893/412916 calling UIColor *color = [[[self class] getRGBAsFromImage:roses atX:0 andY:0 count:1] objectAtIndex:0]; – Jano May 20 '13 at 12:16