Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Possible to extract color values from a bitmap image?
Started by borderleap Nov 20 2019 06:54 AM

- - - - -
10 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

borderleap

[GLOBAL: userInfoPane.html]
borderleap
  • Contributor

  • 406 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 781 posts
  • Corona SDK

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()



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 781 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 268 posts
  • Corona SDK

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


  • pixec likes this

[TOPIC: post.html]
#5

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 781 posts
  • Corona SDK

@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 say Corona's memoryBitmap?  I think either one would be a smarter approach than the solution I offered above.



[TOPIC: post.html]
#6

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 268 posts
  • Corona SDK

@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 say Corona'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.


  • sporkfin likes this

[TOPIC: post.html]
#7

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 842 posts
  • Corona SDK

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.



[TOPIC: post.html]
#8

borderleap

[GLOBAL: userInfoPane.html]
borderleap
  • Contributor

  • 406 posts
  • Corona SDK

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.



[TOPIC: post.html]
#9

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 268 posts
  • Corona SDK

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.



[TOPIC: post.html]
#10

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 173 posts
  • Corona SDK

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

[TOPIC: post.html]
#11

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 781 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]