嘿,我在应用程序中实现了涂鸦功能。画线时,移动手指时看不到线路径。我可以看到线条向上的时间,例如TouchUp,有人可以帮助我,以便我可以看到沿着路径移动手指时绘制的线条。
public class DoodleImageView extends View {
// drawing path
private Path drawPath;
// drawing point
private boolean drawPoint;
// drawing and canvas paint
public Paint drawPaint;
public Paint tempPaint;
private Paint canvasPaint;
// initial color
private int paintColor;
// canvas
private Canvas drawCanvas;
// canvas bitmap
private Bitmap canvasBitmap;
private ArrayList<Path> paths = new ArrayList<Path>();
private ArrayList<Integer> pathscolor = new ArrayList<Integer>();
private ArrayList<Integer> pointcolor = new ArrayList<Integer>();
private ArrayList<Integer> marker = new ArrayList<Integer>();
private ArrayList<Point> points = new ArrayList<Point>();
private float mX, mY;
private final float TOUCH_TOLERANCE = 1;
public DoodleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setupDrawing();
// TODO Auto-generated constructor stub
}
private void setupDrawing() {
// get drawing area setup for interaction
drawPath = new Path();
drawPaint = new Paint();
// drawPaint.setColor(paintColor);
drawPaint.setAntiAlias(true);
drawPaint.setStrokeWidth(20);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeJoin(Paint.Join.ROUND);
drawPaint.setStrokeCap(Paint.Cap.ROUND);
canvasPaint = new Paint(Paint.DITHER_FLAG);
}
private Paint setUpPaint(int color) {
tempPaint = new Paint();
tempPaint.setColor(color);
tempPaint.setAntiAlias(true);
tempPaint.setStrokeWidth(20);
tempPaint.setStyle(Paint.Style.STROKE);
tempPaint.setStrokeJoin(Paint.Join.ROUND);
tempPaint.setStrokeCap(Paint.Cap.ROUND);
return tempPaint;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
if (marker.size() > 0) {
for (int i = 0; i < paths.size(); i++) {
canvas.drawPath(paths.get(i), setUpPaint(pathscolor.get(i)));
}
for (int i = 0; i < points.size(); i++) {
canvas.drawPoint(points.get(i).x, points.get(i).y,
setUpPaint(pointcolor.get(i)));
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float touchX = event.getX();
float touchY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
default:
return false;
}
invalidate();
return true;
}
private void touch_start(float x, float y) {
drawPoint = true;
drawPath.reset();
drawPath.moveTo(x, y);
drawCanvas.drawPath(drawPath, drawPaint);
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) {
drawPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
drawPoint = false;
drawCanvas.drawPath(drawPath,drawPaint);
mX = x;
mY = y;
}
}
private void touch_up() {
if (drawPoint == true) {
drawCanvas.drawPoint(mX, mY, drawPaint);
Point p = new Point();
p.set((int) mX, (int) mY);
points.add(p);
pointcolor.add(drawPaint.getColor());
marker.add(0);
} else {
drawPath.lineTo(mX, mY);
drawCanvas.drawPath(drawPath, drawPaint);
paths.add(drawPath);
drawPath = new Path();
drawPath.reset();
pathscolor.add(drawPaint.getColor());
marker.add(1);
}
}
public void clear() {
if (marker.size() > 0) {
paths.clear();
points.clear();
pathscolor.clear();
pointcolor.clear();
invalidate();
}
}
public void undo() {
if (marker.size() > 0) {
if (marker.get(marker.size() - 1) == 1) {
if (paths.size() > 0) {
paths.remove(paths.size() - 1);
pathscolor.remove(pathscolor.size() - 1);
marker.remove(marker.size() - 1);
invalidate();
}
} else {
if (points.size() > 0) {
points.remove(points.size() - 1);
pointcolor.remove(pointcolor.size() - 1);
marker.remove(marker.size() - 1);
invalidate();
}
}
}
}
}
public class DoodleImageView extends View {
// drawing path
private Path drawPath;
// drawing point
private boolean drawPoint;
// drawing and canvas paint
public Paint drawPaint;
public Paint tempPaint;
private Paint canvasPaint;
// initial color
private int paintColor;
// canvas
private Canvas drawCanvas;
// canvas bitmap
private Bitmap canvasBitmap;
private ArrayList<Path> paths = new ArrayList<Path>();
private ArrayList<Integer> pathscolor = new ArrayList<Integer>();
private ArrayList<Integer> pointcolor = new ArrayList<Integer>();
private ArrayList<Integer> marker = new ArrayList<Integer>();
private ArrayList<Point> points = new ArrayList<Point>();
private float mX, mY;
private final float TOUCH_TOLERANCE = 1;
public DoodleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setupDrawing();
// TODO Auto-generated constructor stub
}
private void setupDrawing() {
// get drawing area setup for interaction
drawPath = new Path();
drawPaint = new Paint();
// drawPaint.setColor(paintColor);
drawPaint.setAntiAlias(true);
drawPaint.setStrokeWidth(20);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeJoin(Paint.Join.ROUND);
drawPaint.setStrokeCap(Paint.Cap.ROUND);
canvasPaint = new Paint(Paint.DITHER_FLAG);
}
private Paint setUpPaint(int color) {
tempPaint = new Paint();
tempPaint.setColor(color);
tempPaint.setAntiAlias(true);
tempPaint.setStrokeWidth(20);
tempPaint.setStyle(Paint.Style.STROKE);
tempPaint.setStrokeJoin(Paint.Join.ROUND);
tempPaint.setStrokeCap(Paint.Cap.ROUND);
return tempPaint;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
if (marker.size() > 0) {
for (int i = 0; i < paths.size(); i++) {
canvas.drawPath(paths.get(i), setUpPaint(pathscolor.get(i)));
}
for (int i = 0; i < points.size(); i++) {
canvas.drawPoint(points.get(i).x, points.get(i).y,
setUpPaint(pointcolor.get(i)));
}
}
canvas.drawPath(drawPath,drawPaint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float touchX = event.getX();
float touchY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
default:
return false;
}
invalidate();
return true;
}
private void touch_start(float x, float y) {
drawPoint = true;
drawPath.reset();
drawPath.moveTo(x, y);
drawCanvas.drawPath(drawPath, drawPaint);
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) {
drawPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
drawPoint = false;
drawCanvas.drawPath(drawPath,drawPaint);
mX = x;
mY = y;
}
}
private void touch_up() {
if (drawPoint == true) {
drawCanvas.drawPoint(mX, mY, drawPaint);
Point p = new Point();
p.set((int) mX, (int) mY);
points.add(p);
pointcolor.add(drawPaint.getColor());
marker.add(0);
} else {
drawPath.lineTo(mX, mY);
drawCanvas.drawPath(drawPath, drawPaint);
paths.add(drawPath);
drawPath = new Path();
drawPath.reset();
pathscolor.add(drawPaint.getColor());
marker.add(1);
}
}
public void clear() {
if (marker.size() > 0) {
paths.clear();
points.clear();
pathscolor.clear();
pointcolor.clear();
invalidate();
}
}
public void undo() {
if (marker.size() > 0) {
if (marker.get(marker.size() - 1) == 1) {
if (paths.size() > 0) {
paths.remove(paths.size() - 1);
pathscolor.remove(pathscolor.size() - 1);
marker.remove(marker.size() - 1);
invalidate();
}
} else {
if (points.size() > 0) {
points.remove(points.size() - 1);
pointcolor.remove(pointcolor.size() - 1);
marker.remove(marker.size() - 1);
invalidate();
}
}
}
}
}
This manual migration process should be run after the automated migration process, to complete the missing parts, or debug issues in the migration CLI output. Project setup package.json Scoped package
问题内容: 以下是我的gulpfile.js。其中还有更多任务,并且所有工作都很好-但最后一个任务却没有。 我已经尝试过路径和文件的所有可能组合,还有其他尝试,但是我还是没有运气。我在这里已经阅读了很多答案,但是无法解决我的问题。我尝试使用gulp- watch和不使用gulp-watch来运行gulp.watch,尝试了几种不同的方法来设置任务,等等。 有人可以提出解决方案吗? 编辑: 这是控制
本文向大家介绍基于Android实现随手指移动的ImageView,包括了基于Android实现随手指移动的ImageView的使用技巧和注意事项,需要的朋友参考一下 ImageView用来显示任意图像图片,可以自己定义显示尺寸,显示颜色等等. 运行效果是这样的(文字说明): 首次进入程序,手指点击屏幕上的任意位置,图片会随之移动。 布局文件 实现代码 以上内容给大家介绍了基于Android实现随
本文向大家介绍Android自定义view圆并随手指移动,包括了Android自定义view圆并随手指移动的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了Android自定义view圆并随手指移动的具体代码,供大家参考,具体内容如下 main代码 布局 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。
本文向大家介绍Django 手动迁移,包括了Django 手动迁移的使用技巧和注意事项,需要的朋友参考一下 示例 有时,由Django生成的迁移是不够的。当您要进行数据迁移时尤其如此。 例如,让我们拥有这样的模型: 该模型已经有现有数据,现在您想添加一个SlugField: 您创建了迁移以添加字段,但是现在,根据它们的,您想为所有现有文章设置标签title。 当然,您可以在终端中执行以下操作: 但
很可惜,苹果官方的 XCTest 框架本身并不支持 TouchAction 接口实现的 W3C 标准。尽管如此,XCTest 提供了非常丰富的手势操作,这些操作都是 iOS 平台独有的。你可以在 1.6.4-beta 版本的 Appium 中开始使用这些手势操作。 需要特别注意的是目前XCTest和WDA正在不断优化改变的阶段,这意味着所有 mobile: * 的命令可能会在没任何通知的情况下就被