Table of Contents
Android 4.4 introduced more subtle use of colour throughout the OS and provided new guidance on using colour in your applications to provide better branding (see this episode of ADiA for more discussion). This means that the onus is now on you as a designer/developer to inject some colour into your app to make it stand out.
Use your brand color for accent by overriding the Android framework’s default blue in UI elements. Android Design site
A simple way to do this is by add a custom background to your Action Bar, but I wanted something a bit more dynamic for an hobby app I’m currently writing. One of the best examples of adapting to colour is iTunes which picks out the colour scheme from an album’s artwork, and then colours the tracklist popout to suit.
So I set about implementing this on Android.
Basic theory #
The first step is the quantization of your source image. In layman terms, this mean decreasing the number of colours used in the image. If you like animated GIFs then you will have seen the effect as GIFs can only have a 8-bit palette, therefore can only use up to 256 discrete colours per frame.
For our purpose, I needed to reduce the palette down even further to a small amount of dominant colours. From there we can take the generated palette and work out the important colours. More on that later.
For now though I had to decide which quantization algorithm to use. Color Thief uses a modified version of Median Cut Quantization (MCQ) ingeniously called Modified Median Cut Quantization (MMCQ). You can find more information on MMCQ here. Other popular quantization techniques include NeuQuant and OctTree
I decided to go with MCQ as it has a few nice characteristics for my purposes:
- It’s quick. Much quicker than NeuQuant, and much much quicker than OctTree. This is obviously important when we’re running on a handheld device.
- Internally it’s uses a histogram, therefore each colour (cube) has a count attached to it. This is handy later on for sorting.
MCQ does not produce the best quality images though, but as I only need the colour palette and don’t display the quantized image; that’s fine.
So here are the results, using Color Thief’s example images. Remember that MCQ uses a histogram? Well we can sort the palette based on how often the colour is used, and it turns out that a simple sorted list of the palette seems to work OK. This can definitely be improved upon though.
The results are slightly different from what Color Thief produces:
- Mine wins as it picks out the blue as the dominant colour.
- Color Thief wins as it picks out the blue, silver and green as the top colours.
- Color Thief wins as it does not pick out varying shades of dark grey. Something to improve upon.
Part 2 of this post will be talk about how to better pick out the dominant colours from the palette, and will be published next week.
Here’s the technique being used in my hobby app. It generates the colour palette from a movie’s poster, and then updates the rating bar to match.
EDIT : You find the second part of this post here: