问题描述
一直很少超过净约DrawFilter讨论,所以我不能找到以下问题一个体面的答案是:
very little has been discussed about DrawFilter over the net, so i couldnt find a decent answer for the following question:
已经documanted 是:
it has been documanted here that:
一个DrawFilter子类可以安装在一个画布。当它是present,它可以修改用于绘制(暂时)的漆。有了这个,过滤器可以禁用/启用抗锯齿,或改变颜色这是绘制一切。
所以我想,以改变的东西在我的画布上绘制黑色的颜色使用此功能,但它怎么办?因为这个类有没有方法来覆盖它的一个RIDLE我应该如何继承它acheive什么documanted ...
So i do want to use this feature in order to change the color things are drawn in my canvas to black, but how is it done? since this class has no methods to override its a ridle how i should subclass it to acheive what is documanted...
BTW,对谁都没见过它,帆布有一个方法canvas.setDrawFilter(DrawFilter)应使用,我想看看开源$ C $ C,但我没有得到一个线索那里...
BTW, to whoever never seen it, canvas has a method canvas.setDrawFilter(DrawFilter) that should be used, i tried to look at the open source code but i didnt get a clue there...
什么想法?
推荐答案
唯一可用的 DrawFilter
似乎是专为在油漆标记:
The only available subclass of DrawFilter
seems to be exclusively for tweaking bits in Paint
flags:
setDrawFilter(新PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG,Paint.DITHER_FLAG))
所以,我怀疑这是多大用处的。
So, I doubt it is of much use.
此外,检查出。和 setSaturation()
的。这可能有助于绘制灰度
Also, check out ColorFilter
. And setSaturation()
of ColorMatrix
. That might help drawing in grayscale.
示例:画一个彩色图像( inImg
)为黑色和白色( outImg
尺寸尺寸
),在画布上:
Example: to draw an colored image (inImg
) as black and white (outImg
of size size
) on a canvas:
Bitmap outImg = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
Canvas can = new Canvas(outImg);
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
Paint pnt = new Paint(Paint.DITHER_FLAG);
pnt.setColorFilter(new ColorMatrixColorFilter(cm));
can.drawBitmap(inImg, 0, 0,pnt);
这篇关于如何使用DrawFilter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!