Possible to extract color values from a bitmap image?

Kinda like this… http://www.coolphptools.com/color_extract.  Is this possible from within Corona?

Yes

  1. You can use display.capture() or display.captureScreen() to make a display object from whatever is on the screen

  2. Analyze the image/object using display.colorSample()

If you want a different color system, you can convert to Hexadecimal or HSL

Sampling form the display isn’t the best option as the results may depend on the filtering and/or scaling of the image and you also need to display the image first (and handle cases where the image is bigger than the actual display resolution).

A probably better alternative is to use Starcrunchs extension https://marketplace.coronalabs.com/corona-plugins/byte-map

@Michael Flad, Ah, that’s a good solution - probably much faster than color samples. 

Is there any reason you would use Starcrunch’s byte-map extension instead of sayCorona’s memoryBitmap?  I think either one would be a smarter approach than the solution I offered above.

As far as I can tell (if I didn’t miss anything in the docs) there’s no way to load image files into a memoryBitmap or transfer the contents of an existing texture into a memoryBitmap. So you’d have to also implement a jpg/png loader to work with existing images.

Basically what @ Michael Flad said.

It’s sort of incidental in my plugin’s case that it can be used to get and set individual pixels, as it’s largely intended for bulk operations like full images or large subregions. It actually began life as some methods added to memory bitmaps, so I do have code somewhere that will populate them from bytes; that’s a recompiled plugin though, not something that could just be dropped in.

Hey thanks everyone for the help!  Overall I’d like to assess the most commonly used colors in an image and develop a color palette of about 7-10 colors max.  I’m thinking performance-wise, it’ll be best to do this outside of Corona and just load those values in.

Of course, if your images are static and nothing where a user would feed in his own content, then a precalculated array of values is the simplest and most efficient solution.

Like Flad said. If you know the colors in the images, or how the colors will be determinned then it is faster to just use table look up or such. Best to do all you can when time isnt important, ie production

I was assuming the images would be dynamic, otherwise, Photoshop can do this procedure for you pre-runtime.

@borderleap - please let us know how you proceed with this, even it it is outside Corona and then fed into the app, I’m very curious about your final solution.