绘制对象=>灰阶 [英] Drawable => grayscale
本文介绍了绘制对象=>灰阶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是正确的方式把一个色可绘制成灰度一(指示禁用状态)?
What would be the right way to turn a color Drawable into a grayscale one (to indicate disabled state)?
编辑:
B / W =>灰度
B/W => grayscale
推荐答案
显然,你可以使用嘉洛斯
类做任何形式的色彩空间转换。它有一个 setSaturation()
的方法,可以轻松地为您创建一个颜色到灰度转换(零饱和度)。
Apparently you can use the ColorMatrix
class to do any sort of color-space transformations. It has a setSaturation()
method that easily creates a color-to-grayscale transformation (zeroes saturation) for you.
所以,你可以使用滤镜来绘制图像的新副本。我没有试过,但它应该工作:
So, you can use that filter to paint a new copy of the image. I haven't tried this, but it should work:
Bitmap grayscaleBitmap = Bitmap.createBitmap(
colorBitmap.getWidth(), colorBitmap.getHeight(),
Bitmap.Config.RGB_565);
Canvas c = new Canvas(grayscaleBitmap);
Paint p = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
p.setColorFilter(filter);
c.drawBitmap(colorBitmap, 0, 0, p);
这篇关于绘制对象=>灰阶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文