Android 如何从 int RGB 中获取红色、绿色和蓝色值?

Android how do I get the red, green and blue value from int RGB?

我正在使用调色板 class 从位图中提取主要的鲜艳颜色,如下所示:

     Palette.generateAsync(drawView.getDrawingCache(), new Palette.PaletteAsyncListener() {
            @Override
             public void onGenerated(Palette palette) {
             int color = palette.getVibrantColor(which);
              }
            });

但我还需要从颜色中获取红色、绿色和蓝色值(在 0-255 范围内)。有什么想法吗?

以下代码将为您提供红色、绿色、蓝色颜色代码:

int color = (int)Long.parseLong(myColorString, 16);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;