如何检测位图图片包含柔和或鲜艳的颜色?
How to detect bitmap picture contain muted or vibrant color?
我用pallete
class设置随机背景色为textview
,有些图片无法生成颜色,return颜色如灰色。我发现一些图像文件与 getMutedColor
一起使用,而另一些图像文件与 getVibrantColor
和其他人一起工作。
这是我的布局。我使用 ImageView
来显示位图,并在其下方使用 TextView
来显示具有随机背景的名称。
我们如何检测图像文件是否使用 `getMutedColor` 或 `getVibrantColor` 或其他?
这是我目前尝试的代码:
public void generateColor(Bitmap mypic){
mImageView.setImageBitmap(result);
Palette p = Palette.from(result).generate();
mTextView.setBackgroundColor(p.getVibrantColor(default_color));
}
非常感谢您的帮助。
我只是检查是否为 null。
public int getSwatch(Bitmap b){
Palette p = Palette.from(b).generate();
Palette.Swatch swatch;
if((swatch = p.getVibrantSwatch()) != null){
return swatch.getRgb();
}
if((swatch = p.getLightMutedSwatch()) != null){
return swatch.getRgb();
}
.
.
.
return Color.WHITE;
}
Color.WHITE
最后是 后备颜色 。如果 Palette
找不到颜色,您仍然会得到 WHITE
作为结果。你可以把它换成任何你想要的颜色。
我用pallete
class设置随机背景色为textview
,有些图片无法生成颜色,return颜色如灰色。我发现一些图像文件与 getMutedColor
一起使用,而另一些图像文件与 getVibrantColor
和其他人一起工作。
这是我的布局。我使用 ImageView
来显示位图,并在其下方使用 TextView
来显示具有随机背景的名称。
我们如何检测图像文件是否使用 `getMutedColor` 或 `getVibrantColor` 或其他?
这是我目前尝试的代码:
public void generateColor(Bitmap mypic){
mImageView.setImageBitmap(result);
Palette p = Palette.from(result).generate();
mTextView.setBackgroundColor(p.getVibrantColor(default_color));
}
非常感谢您的帮助。
我只是检查是否为 null。
public int getSwatch(Bitmap b){
Palette p = Palette.from(b).generate();
Palette.Swatch swatch;
if((swatch = p.getVibrantSwatch()) != null){
return swatch.getRgb();
}
if((swatch = p.getLightMutedSwatch()) != null){
return swatch.getRgb();
}
.
.
.
return Color.WHITE;
}
Color.WHITE
最后是 后备颜色 。如果 Palette
找不到颜色,您仍然会得到 WHITE
作为结果。你可以把它换成任何你想要的颜色。