正如您在我的应用程序中使用canvas.drawpath()
时所看到的那样,我得不到一个用户想要的结果。
查看我的手指在哪里以及它在哪里绘制!
//Bitmap is the picture
imageview.setImageBitmap(bitmap);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.Black);
paint.setStrokeWidth(50);
paint.setStyle(Paint.Style.STROKE);
path = new Path();
imageview.setOnTouchListener(this);
这里是onTouchListener
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
path.moveTo(event.getX(), event.getY());
path.lineTo(event.getX(), event.getY());
canvas.drawPath(path, paint);
imageview.invalidate();
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(event.getX(), event.getY());
canvas.drawPath(path, paint);
imageview.invalidate();
break;
case MotionEvent.ACTION_UP:
path.lineTo(event.getX(), event.getY());
canvas.drawPath(path, paint);
imageview.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
答案 0 :(得分:0)
实际上我的问题是我无法获得真实的x和y位置。
要实现这一点很简单,你可以在没有先生pskink帮助的情况下单独完成
Matrix official= new Matrix();
image.getImageMatrix().invert(official);
float[] REALXY= new float[] {documentation.getX(), documentation.getY()};
official.mapPoints(REALXY);
float GETREALX;
GETREALX=REALXY[0];
float GETREALY;
GETREALY= REALXY[1];