gpt4 book ai didi

安卓绘画/ Canvas 问题;绘制平滑曲线

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:59 28 4
gpt4 key购买 nike

当我在 Android 中用手指在触摸屏上绘图时,如何获得平滑的曲线而不是点或圆?我正在使用以下代码-

public class DrawView extends View implements OnTouchListener {
private static final String TAG = "DrawView";

List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();

public DrawView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);

this.setOnTouchListener(this);

paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
}

@Override
public void onDraw(Canvas canvas) {
for (Point point : points) {
canvas.drawCircle(point.x, point.y, 5, paint);
// Log.d(TAG, "Painting: "+point);
}
}

public boolean onTouch(View view, MotionEvent event) {
// if(event.getAction() != MotionEvent.ACTION_DOWN)
// return super.onTouchEvent(event);
Point point = new Point();
point.x = event.getX();
point.y = event.getY();
points.add(point);
invalidate();
Log.d(TAG, "point: " + point);
return true;
}
}

class Point {
float x, y;

@Override
public String toString() {
return x + ", " + y;
}
}

最佳答案

有一个与 API 演示包 bundle 在一起的 FingerPaint 应用程序;你可以看看那个。这是 link

关于安卓绘画/ Canvas 问题;绘制平滑曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2639002/

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