gpt4 book ai didi

java - Android的Canvas.drawBitmap()方法中参数 ‘Paint’的作用

转载 作者:行者123 更新时间:2023-11-30 02:44:15 46 4
gpt4 key购买 nike

我试图阅读 Android SDK 中的示例 FingerPaint,其中方法 canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint) 中调用onDraw().

我被参数mBitmapPaint搞糊涂了。当我更改mBitmapPaint的设置时似乎没有效果。位图在屏幕上绘制的样式只取决于在别处定义的mPaint 的设置。 Google的Android Reference说参数paint可能为null,是不是说明这里的paint没用?为什么要在这个方法中放一个 paint 参数?

声明为:

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

/*
* Set the styles of mPaint here
* ......
*/

// Settings of mBitmapPaint seem to make no difference
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);
}

最佳答案

Bitmap 的绘制几乎没有用,我认为适用于 Bitmap 的绘制对象的唯一参数是 AntiAliasing 模式,默认情况下是打开的。我认为您也可以将颜料用于滤色器,例如黑色和白色,但在大多数情况下,您也可以只使用 null

关于java - Android的Canvas.drawBitmap()方法中参数 ‘Paint’的作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25327299/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com