This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<link | |
href="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.11.7/video-js.min.css" | |
rel="stylesheet" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |