我正在尝试使用Paint ColorFilter来反转位图。我使用了这个链接作为参考:http://www.mail-archive.com/android-developers@googlegroups.com/msg47520.html,但是它没有任何效果——位图正常绘制。你能告诉我我做错了什么吗?
定义float数组:
定义float数组:
float invert [] = {
-1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f
};
在构造函数中设置Paint
ColorMatrix cm = new ColorMatrix(invert);
invertPaint.setColorFilter(new ColorMatrixColorFilter(cm));
Draw() 方法中的引用
c.drawBitmap(Bitmap, null, Screen, invertPaint);
编辑:我通过在绘制语句中进行颜色赋值来使其正常工作:
ColorMatrix cm = new ColorMatrix(invert);
invertPaint.setColorFilter(new ColorMatrixColorFilter(cm));
c.drawBitmap(rm.getBitmap(DefaultKey), null, Screen, invertPaint);
但现在它的渲染速度非常慢(可能是因为每一帧都要设置一个复杂的矩阵)...它在相同的方法中工作时有原因吗?
编辑2: 算了吧!哈哈,问题是我有两个构造函数,而我只在其中一个中配置了颜色过滤器...这个过程仍然非常耗费CPU资源,并导致帧速率下降。