diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java index a6e25ad..eaf49ad 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintCanvas.java @@ -14,9 +14,9 @@ import org.ntlab.acanthus_client.entities.Position; import org.ntlab.acanthus_client.entities.Stroke; -import org.ntlab.acanthus_client.views.paint.page.Point; import java.io.ByteArrayOutputStream; +import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -38,6 +38,8 @@ private int localstrokeNo = 0; private Canvas curCanvas; private Bitmap image; + private Point curpoint; + private ArrayList pts; //----------------------------------------------------------------- //----------------------------------------------------------------- @@ -56,7 +58,8 @@ paint2.setStrokeWidth(20);//幅 image = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888); curCanvas = new Canvas(image); - + pts=new ArrayList<>(); + Point curpoint= new Point(); thread.scheduleWithFixedDelay(this, 1000L, 2000L, TimeUnit.MILLISECONDS); invalidate(); @@ -116,6 +119,8 @@ case MotionEvent.ACTION_UP: Log.d("motion", "=====================================up======================================================"); paintViewModel.addPositionRequestFirst(); + drawCanvas(); + pts.clear(); break; } @@ -137,6 +142,9 @@ private void onTouched(float x, float y) { //path = new Path(); path.moveTo(x, y); + curpoint.setX(x); + curpoint.setY(y); + pts.add(curpoint); invalidate(); } @@ -144,6 +152,9 @@ // 押した後動かした時の処理 private void onTouchedMove(float x, float y) { path.lineTo(x, y); + curpoint.setX(x); + curpoint.setY(y); + pts.add(curpoint); invalidate(); } @@ -227,7 +238,7 @@ getCanvas(); } - private void drawCanvas(Canvas canvas, List pts){ + private void drawCanvas(){ if (pts.size() > 1){ Path path = new Path(); final int SMOOTH_VAL = 6; @@ -266,11 +277,11 @@ path.cubicTo(prev.getX() + prev.getDx(), prev.getY() + prev.getDy(), point.getX() - point.getDx(), point.getY() - point.getDy(), point.getX(), point.getY()); } } - canvas.drawPath(path, paint); + curCanvas.drawPath(path, paint); } else { if (pts.size() == 1) { Point point = pts.get(0); - canvas.drawCircle(point.getX(), point.getY(), 2, paint); + curCanvas.drawCircle(point.getX(), point.getY(), 2, paint); } } }