Tuesday, 27 August 2013

Difference in coordinates of motionEvent and drawLine on a scaled image

Difference in coordinates of motionEvent and drawLine on a scaled image

I try to paint a line this way:
@Override
public boolean onTouch(View view, MotionEvent event) {
int action = event.getAction();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(1);
canvas.setBitmap(rotatedBitmap);
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawBitmap(notChangedRotatedBitmap, new
Matrix(), paint);
canvas.drawLine(downx / 2, downy / 2, upx / 2, upy /
2, paint);
photoView.invalidate();
break;
case MotionEvent.ACTION_UP:
canvas.drawBitmap(notChangedRotatedBitmap, new
Matrix(), paint);
photoView.invalidate();
float degree = getDegree(downx, downy, upx, upy);
rotateBy(degree);
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
It draws ok if I use not changed bitmap.
But if the image is scaled either by bitmapOptions in
BitmapFactory.decodeStream(input, null, bitmapOptions);
or any other way like
Bitmap.createBitmap(rotatedBitmap, (int) shiftDistanceSide, (int)
shiftDistanceTop, rotatedBitmap.getWidth() - 2 * (int) shiftDistanceSide,
rotatedBitmap.getHeight() - 2 * (int) shiftDistanceTop);
The coordinates of the motionEvent seem to be multiplied by a factor, may
be zoom factor. How to avoid it?

No comments:

Post a Comment