gpt4 book ai didi

android - 是否可以使用 android.graphics.Path 绘制点

转载 作者:搜寻专家 更新时间:2023-11-01 09:01:38 26 4
gpt4 key购买 nike

我正在编写简单的 android 应用程序,用于基于 FingerPaint API 演示示例在屏幕上绘图。在演示中,仅当手指在屏幕上移动了由 TOUCH_TOLERANCE 定义的一定距离后,绘图才会开始。即使用户不移动手指,我也想画一个点。可能吗?

    @Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}

private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
//mPath.lineTo(x + 1, y + 1); //quick fix
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}

最佳答案

是的,这是可能的。只需将 1 添加到 xy像这样

//Create a dot
path.setLastPoint(x, y);
x++;
path.lineTo(x, y);

关于android - 是否可以使用 android.graphics.Path 绘制点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696325/

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