2021/02/22

Extract dominant color from image

How to extract dominant color from image ?
     
File f = new File(path);
BitmapFactory.Options o = new BitmapFactory.Options();
o.inSampleSize = 16;
try {
    Bitmap bitmap = BitmapFactory.decodeStream(f.getInputStream(), null, o);
    if (bitmap != null) {
        Palette palette = Palette.from(bitmap).generate();
        palette.getDominantSwatch() // dominant color
    }
} catch (IOException ignored) {
}

沒有留言:

張貼留言