如何使用DrawFilter? [英] how to use DrawFilter?

查看:1327
本文介绍了如何使用DrawFilter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直很少超过净约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,它可以修改用于绘制(暂时)的漆。有了这个,过滤器可以禁用/启用抗锯齿,或改变颜色这是绘制一切。

A DrawFilter subclass can be installed in a Canvas. When it is present, it can modify the paint that is used to draw (temporarily). With this, a filter can disable/enable antialiasing, or change the color for everything this is drawn.

所以我想,以改变的东西在我的画布上绘制黑色的颜色使用此功能,但它怎么办?因为这个类有没有方法来覆盖它的一个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,Pa​​int.DITHER_FLAG))

所以,我怀疑这是多大用处的。

So, I doubt it is of much use.

此外,检查出 Col​​orFilter 。和<一个href=\"http://developer.android.com/reference/android/graphics/ColorMatrix.html#setSaturation%28float%29\"相对=nofollow> 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆