5

I have recently been playing with Bitmaps and palettes when I encountered the following:

java.lang.IllegalArgumentException: background can not be translucent
    at android.support.v7.graphics.ColorUtils.findMinimumAlpha(ColorUtils.java:90)
    at android.support.v7.graphics.ColorUtils.getTextColorForBackground(ColorUtils.java:127)
    at android.support.v7.graphics.Palette$Swatch.ensureTextColorsGenerated(Palette.java:621)
    at android.support.v7.graphics.Palette$Swatch.getTitleTextColor(Palette.java:605)

Diving into the source code, I found:

private static int findMinimumAlpha(int foreground, int background, double minContrastRatio) {
    if (Color.alpha(background) != 255) {
        throw new IllegalArgumentException("background can not be translucent");
    }
    ...
}

The image I was using is this:

a simple actionbar search icon original icon

I think the problem has to do with how this image is entirely transparent to some degree. I am currently implementing a nearly identical check as the throw clause Color.alpha(palette.getSomeColor()) != 255, but this just feels wrong.

Is there a method when dealing with Palettes that solves this problem for me? I feel as though it would be a common enough error that I must be doing something wrong, or missed some guide about this.

ByteHamster
  • 4,884
  • 9
  • 38
  • 53
Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60

0 Answers0