我正在尝试为我的 Android 绘画应用程序制作自定义画笔。我从 Michael 的代码(在此处找到)开始,我设法获得了 .png 画笔并将其用作位图并重绘它。它工作正常,但我不能改变颜色。尝试使用setcolorfilter
andcolormatrixfilter
但它似乎不起作用。任何人都知道我该怎么做?
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 函数出现错误。