8

I am currently working with the Palette API from support library (https://developer.android.com/tools/support-library/features.html#v7-palette)

The code below works fine with hundreds of pictures, no problem at all. I set the text and background color depending on the palette results. The result is awesome and really nice looking (if you want to re-use it in your application, do not hesitate!).

Unfortunately, in hundreds of pictures, only one is not working and gives weird results. This is this one => http://www.cineswellington.com/images/film/140929075044.jpg

As the Palette has no documentation or debug mode, I really wonder what could happen, and if there is a way to understand if there is a flaw in the original picture or whatever.

Picasso.with(getActivity()).load("http://www.cineswellington.com/images/film/140929075044.jpg").into(t);

private Target t = new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
            public void onGenerated(Palette palette) {
                ((ImageView) v.findViewById(R.id.iv)).setImageDrawable(new BitmapDrawable(bitmap));
                //At this point, the ImageView is correctly filled, so the bitmap object has no issue.
                int textColor = palette.getLightMutedColor(android.R.color.darker_gray);
                int bgColor = palette.getDarkMutedColor(android.R.color.white);
                Log.d("CVE","textColorInt: "+ textColor);
                Log.d("CVE","bgColorInt: "+bgColor);
                Log.d("CVE","textColorHexa: "+String.format("#%06X", 0xFFFFFF & textColor));
                Log.d("CVE","bgColorHexa: "+String.format("#%06X", 0xFFFFFF & bgColor));
            }
        });


    }
};

And this is the output:

textColorInt: 17170432
bgColorInt: 17170443
textColorHexa: #060000
bgColorHexa: #06000B

If someone could help me to reproduce the bug or tell me that it's only happening on my side, this would be awesome

Waza_Be
  • 39,407
  • 49
  • 186
  • 260

2 Answers2

4

The image seems to consist of vibrant colors only, so it'd be hard to create a muted color palette that would fit it. It's not surprising the algorithm fails to do so.

Try using the getVibrantColor() functions if muted dark/light are too much alike.

ovikoomikko
  • 577
  • 6
  • 11
  • 1
    The muted color is not null, some results are sent... And event if they were null, there is the default color I specified... – Waza_Be Nov 12 '14 at 18:30
  • Probably there are some colors in the muted range (due to the transparent red flames), so the those are returned. I'd guess it just returns the darkest and lightest colors in the palette that are in the muted range – ovikoomikko Nov 13 '14 at 16:05
0

I guess there is no minimal color differences between 'light muted' and 'dark muted' colors in the Palette algorithm i.e. one is not supposed to be used as text color on top of the other.

In Romain Guy's demo at Google IO, he used 'light muted' for background and 'light vibrant' for text color.

Shouldn't you use a vibrant color for your text instead ?

JeromePApp
  • 209
  • 1
  • 6