我正在尝试为我的Android绘画应用制作自定义画笔。我从迈克尔的代码(found here)开始,我设法得到.png画笔并将其用作位图并重新绘制。它工作正常,但我无法改变颜色。尝试使用setcolorfilter
和colormatrixfilter
,但它似乎不起作用。谁知道我怎么能这样做?
private Bitmap mBitmapBrush;
private Vector2 mBitmapBrushDimensions;
private List<Vector2> mPositions = new ArrayList<Vector2>(100);
private Paint mPanit;
public MyView(Context c) {
super(c);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mBitmapBrush = BitmapFactory.decodeResource(c.getResources(),R.drawable.brush1);
mBitmapBrushDimensions = new Vector2(mBitmapBrush.getWidth(), mBitmapBrush.getHeight());
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
for (Vector2 pos : mPositions) {
canvas.drawBitmap(mBitmapBrush, pos.a, pos.b, mPanit);
}
invalidate();
}
当我尝试使用Colormatrixfilter时,.set函数发出错误。
答案 0 :(得分:1)