/** * 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); } }
FeedColors(@Nullable @ColorInt Integer color) { final Palette.Swatch swatch; if(color != null) { swatch = new Palette.Swatch(color, 1); } else { swatch = null; } if(swatch != null) palette = new Palette.Builder(Collections.singletonList(swatch)).addTarget(Target.MUTED).generate(); else palette = null; }
private void generatePalette(Bitmap bitmap, Palette.Filter filter, Palette.PaletteAsyncListener paletteAsyncListener) { new Palette.Builder(bitmap) .addFilter(filter) .generate(paletteAsyncListener); }
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { SlideFragment.this.bitmap = bitmap; applyImage(); paletteTask = new Palette.Builder(bitmap) .maximumColorCount(32) .generate(SlideFragment.this); } });
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); }