Android ApiDemos示例解析(59):Graphics->ColorFilters
Android ApiDemos示例解析(59):Graphics->ColorFilters
本例ColorFilters和下例ColorMatrix 涉及到图像处理中的很多专业术语:
Dither(图像的抖动处理,当每个颜色值以低于8位表示时,对应图像做抖动处理可以实现在可显示颜色总数比较低(比如256色)时还保持较好的显示效果: Dither on Wikipedia
 Porter Duff Color Filter 也可以为Alpha Composting,指当在将一幅图像绘制在已有背景图像时如果融合前景和背景颜色的过程。Porter Duffer 定义了多种模式,每种模式使用不同的前景和背景色组合算法: Alpha Composting on Wikipedia
Porter Duff Color Filter 也可以为Alpha Composting,指当在将一幅图像绘制在已有背景图像时如果融合前景和背景颜色的过程。Porter Duffer 定义了多种模式,每种模式使用不同的前景和背景色组合算法: Alpha Composting on Wikipedia
Android中的类PorterDuffColorFilter 定义了Port Duff Color Filter, 例子使用八种不同的颜色两种模式: 其中颜色为0时,对应的colorFilter为null.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | mColors = newint[] { 0, 0xCC0000FF, 0x880000FF, 0x440000FF, 0xFFCCCCFF, 0xFF8888FF, 0xFF4444FF,};mModes = newPorterDuff.Mode[] { PorterDuff.Mode.SRC_ATOP, PorterDuff.Mode.MULTIPLY,}; | 
对于每个ColorFilter调用drawSample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | privatevoiddrawSample(Canvas canvas, ColorFilter filter) { Rect r = mDrawable.getBounds(); floatx = (r.left + r.right) * 0.5f; floaty = (r.top + r.bottom) * 0.5f - mPaintTextOffset; mDrawable.setColorFilter(filter); mDrawable.draw(canvas); canvas.drawText("Label", x+1, y+1, mPaint2); canvas.drawText("Label", x, y, mPaint); for(Drawable dr : mDrawables) { dr.setColorFilter(filter); dr.draw(canvas); }} | 
ColorFilter的效果可以从文字“Label”来看,两行文字只偏移了一个像素,有重叠来看ColorFilter的不同效果,对应SRC_ATOP和MULTIPLY两种模式,文字有可以以白色和黑色显示:
 感觉文字Lable在MULTIPLY模式下”Label”有点“凹下”的效果。除了SRC_ATOP和MULTIPLY之外,PorterDuff.Mode还定义定义了10多种不同模式:
感觉文字Lable在MULTIPLY模式下”Label”有点“凹下”的效果。除了SRC_ATOP和MULTIPLY之外,PorterDuff.Mode还定义定义了10多种不同模式:
 
                     
                    
                 
                    
                

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号