/** * Determines if a given bitmap is dark. This extracts a palette inline so should not be called * with a large image!! If palette fails then check the color of the specified pixel */ public static boolean isDark(@NonNull Bitmap bitmap, int backupPixelX, int backupPixelY) { // first try palette with a small color quant size Palette palette = Palette.from(bitmap).maximumColorCount(3).generate(); if (palette != null && palette.getSwatches().size() > 0) { return isDark(palette) == IS_DARK; } else { // if palette failed, then check the color of the specified pixel return isDark(bitmap.getPixel(backupPixelX, backupPixelY)); } }
public int getStationImageColor() { // extract color palette from station image Palette palette = Palette.from(mInputImage).generate(); // get muted and vibrant swatches Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); Palette.Swatch mutedSwatch = palette.getMutedSwatch(); if (vibrantSwatch != null) { // return vibrant color int rgb = vibrantSwatch.getRgb(); return Color.argb(255, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } else if (mutedSwatch != null) { // return muted color int rgb = mutedSwatch.getRgb(); return Color.argb(255, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } else { // default return return mContext.getResources().getColor(R.color.transistor_grey_lighter); } }
public static int getColor(Bitmap bitmap, boolean incognito) { Palette palette = Palette.from(bitmap).generate(); final int fallback = Color.TRANSPARENT; return incognito ? palette.getMutedColor(fallback) : palette.getVibrantColor(fallback); }