android canvas.drawbitmap 参数,Android的Canvas.drawBitmap()方法,Paint参数的作用是什么
FingerPaint这个示例中,onDraw()里面调用了这个方法canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);但是好像改变mBitmapPaint的样式对最终画出的图像没有影响,官方里也说Paint参数可以为null,那么传这个参数到底有什么用?官方文档节选:public void drawBitmap (Bitmap bitmap, float
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);
}
更多推荐
所有评论(0)