1

From a fragment, I am trying to extract some colors from an image using the Palette class:

Bitmap snap = BitmapFactory.decodeResource(getActivity().getResources(),
R.drawable.snapghostyellow);

Palette palette = Palette.generate(snap);

Palette.Swatch vibrant = palette.getVibrantSwatch();

if(vibrant != null) {
    Log.d("rgb_output", "vibrant Not Null " + Integer.toString(vibrant.getRgb()));
}

However the return of getRgb() is in this case -1024. The problem also occurs with other swatches (e.g. getDarkVibrantSwatch).

Trying to use the outputs crashes the app.

Any suggestions to what is wrong?

Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57
  • "However the return of getRgb() is in this case -1024." -- that's not strictly a problem. Try `toHexString()` instead of `toString()`. "Trying to use the outputs crashes the app" -- use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Aug 02 '15 at 18:16
  • Ah, you are right. `toHexString()` gives fffffc00. And from the LogCat i saw that I was trying to use the int as a resource, which gave the error. I moved the code to my adapter and used `setBackgroundColor()` instead of `setBackgroundResource()`. Thank you CommonsWare – Nicolai Lissau Aug 02 '15 at 21:41

0 Answers0