android 白色drawable,在Android @ drawable中查找图像的主要颜色

在Android 5.0 Lollipop中,添加了一个类来帮助从Bitmap中提取有用的颜色。在android.support.v7.graphics中找到的

Palette类可以提取以下颜色:

充满活力

充满活力的黑暗

充满活力的光

>静音

静音黑暗

静音灯

去引用:

The Android Support Library r21 and above includes the 07000

class, which lets you extract prominent colors from an image. To

extract these colors, pass a Bitmap object to the Palette.generate()

static method in the background thread where you load your images. If

you can’t use that thread, call the Palette.generateAsync() method and

provide a listener instead.*

You can retrieve the prominent colors from the image using the getter

methods in the Palette class, such as Palette.getVibrantColor.

To use the Palette class in your project, add the following Gradle

dependency to your app’s module:

06000

*如果您需要使用generateAsync(),请按以下步骤操作:

Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {

public void onGenerated(Palette palette) {

// Do something with colors...

}

});

编辑:

由于该问题询问如何从可绘制的资源中提取颜色,因此您首先必须将drawable转换为位图以使用我所描述的技术。幸运的是,使用BitmapFactory非常简单:

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),

R.drawable.icon_resource);`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值