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);

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐