android canvas.drawbitmap 参数,Android的Canvas.drawBitmap()方法,Paint参数的作用是什么

FingerPaint这个示例中,onDraw()里面调用了这个方法

canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

但是好像改变mBitmapPaint的样式对最终画出的图像没有影响,官方里也说Paint参数可以为null,那么传这个参数到底有什么用?

官方文档节选:

public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)

Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.

Parameters

bitmap The bitmap to be drawn

left The position of the left side of the bitmap being drawn

top The position of the top side of the bitmap being drawn

paint The paint used to draw the bitmap (may be null)

代码有点长,就改短了贴上来:

private Bitmap mBitmap;

private Canvas mCanvas;

private Path mPath;

private Paint mBitmapPaint;

mPaint = new Paint();

mPath = new Path();

mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

mCanvas = new Canvas(mBitmap);

/*

* 设置mPaint的样式

* ......

*/

mBitmapPaint = new Paint(Paint.DITHER_FLAG);//这里不管怎么设置都不影响最终图像

@Override

protected void onDraw(Canvas canvas) {

canvas.drawColor(0xFFAAAAAA);

canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

canvas.drawPath(mPath, mPaint);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值