Finding the dominant color of an image in an Android @drawable

后端 未结 8 833
情深已故
情深已故 2020-11-28 20:42

You can understand why I\'m trying to find the dominant color in an image if you use Windows 7. When your mouse over a program in the taskbar, the background of that partic

8条回答
  •  不思量自难忘°
    2020-11-28 21:05

    Add to dependencies

    implementation 'androidx.palette:palette:1.0.0'
    

    and..

     AppCompatImageView imageView = findViewById(R.id.image_view);
    
     Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
     Palette.from(bitmap).generate(palette -> {
          int vibrant = palette.getVibrantColor(0x000000); // <=== color you want
          int vibrantLight = palette.getLightVibrantColor(0x000000);
          int vibrantDark = palette.getDarkVibrantColor(0x000000);
          int muted = palette.getMutedColor(0x000000);
          int mutedLight = palette.getLightMutedColor(0x000000);
          int mutedDark = palette.getDarkMutedColor(0x000000);
     });
    

提交回复
热议问题