1

How would you detect the predominant color of the screen (of your app) efficiently in Android, without assuming anything about the views on the screen?

I figure the first step would be generating a bitmap from the screen although I don't know if there's a more efficient way to access the screen pixels.

For the second step I was thinking of scaling the bitmap to a 1x1 pixel and let the platform do the detection work for me, but I'm not sure if this is possible in Android.

hpique
  • 119,096
  • 131
  • 338
  • 476

1 Answers1

0

You could try using getDrawingCache to generate a Bitmap from the root layout (and no, you don't need root for this, at least inside your own app). Here's an example from the Android source's tests that shows how to do something like that.

If you wanted to work on other people's apps, though, you'll need screenshot ability, which requires root permissions.

Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
  • What about detecting the predominant color from the bitmap? – hpique Mar 30 '11 at 17:51
  • That depends on how you define "predominant color." If you just mean the straight RGB value that occurs most frequently without quantizing or anything, then looping through the pixels should be pretty straightforward. If you want something more complicated/interesting, you may find this SO question useful: http://stackoverflow.com/questions/1106190/algorithm-challenge-generate-color-scheme-from-an-image – Yoni Samlan Mar 30 '11 at 19:52