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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With