Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Wubba Lubba dub-dub

Sagar More animsh

🚀
Wubba Lubba dub-dub
View GitHub Profile
@animsh
animsh / PickDominantColorFromBitmap.java
Created Dec 19, 2020
Pick dominant color from bitmap
View PickDominantColorFromBitmap.java
public static int getDominantColor(Bitmap bitmap) {
if (bitmap == null) {
return Color.TRANSPARENT;
}
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int size = width * height;
int pixels[] = new int[size];
//Bitmap bitmap2 = bitmap.copy(Bitmap.Config.ARGB_4444, false);
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
@animsh
animsh / PickDominantColor.java
Created Dec 19, 2020 — forked from KKorvin/PickDominantColor.java
How to pick dominant color from image on Android. Palette Google library used.
View PickDominantColor.java
// Don't forget to add Palette library to your build.gradle
// compile 'com.android.support:palette-v7:+'
public static int getDominantColor(Bitmap bitmap) {
List<Palette.Swatch> swatchesTemp = Palette.from(bitmap).generate().getSwatches();
List<Palette.Swatch> swatches = new ArrayList<Palette.Swatch>(swatchesTemp);
Collections.sort(swatches, new Comparator<Palette.Swatch>() {
@Override
public int compare(Palette.Swatch swatch1, Palette.Swatch swatch2) {
return swatch2.getPopulation() - swatch1.getPopulation();