Вы должны иметь класс краски первый
paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setPathEffect(new DashPathEffect(new float[]{15.0f, 15.0f}, 0));
и осуществить следующее onTouchListener
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
clipPath = new Path();
clipPath.moveTo(downx, downy);
tdownx = downx;
tdowny = downy;
smallx = downx;
smally = downy;
largex = downx;
largey = downy;
lastTouchDown = System.currentTimeMillis();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
cropModelArrayList.add(new CropModel(upx, upy));
clipPath = new Path();
clipPath.moveTo(tdownx,tdowny);
for(int i = 0; i<cropModelArrayList.size();i++){ clipPath.lineTo(cropModelArrayList.get(i).getY(),cropModelArrayList.get(i).getX( ));
}
canvas.drawPath(clipPath, paint);
im_crop_image_view.invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
if (System.currentTimeMillis() - lastTouchDown < CLICK_ACTION_THRESHHOLD) {
cropModelArrayList.clear();
initcanvas();
int cx = (screen_width - bmp.getWidth()) >> 1;
int cy = (screen_height - bmp.getHeight()) >> 1;
canvas.drawBitmap(bmp, cx, cy, null);
im_crop_image_view.setImageBitmap(alteredBitmap);
} else {
if (upx != upy) {
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
clipPath.lineTo(upx, upy);
yourview.invalidate();
}
}
break;
return true;
}
Вы можете найти полную реализацию here(ignore the crop method)
Возможный дубликат [Draw в Canvas пальцем, Android] (http://stackoverflow.com/questions/16650419/draw-in-canvas-by-finger- андроид) – naXa