如何找到旋转文本的位置?
how to find the position of a rotated text?
例如这是我的图片
我知道文本的高度和宽度以及它旋转了多少(角度)我也知道文本的左上角在哪里,如果它没有旋转例如:
我也知道文本围绕其旋转的文本中心的位置,并且该位置在旋转过程中不会改变
现在我需要知道用户是否点击了图像,它是否在文本上,如果是,我还需要知道偏移量
编辑
这里是负责旋转和定位文本位图的代码
public Bitmap getFullTextBitmap2(Bitmap hostBitmap) {
Bitmap tempTextBitmap = getTextBitmap(); // getting the bitmap which only contain the text and has the height and width of the text
Bitmap fullTextBitmap = hostBitmap.copy(hostBitmap.getConfig(), true);
Canvas canvas = new Canvas(fullTextBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(tilt - 180, textWidth / 2, textHeight / 2);
matrix.postTranslate(position.getLeft(), position.getTop());
if (isSelected) {
Canvas textCanvas = new Canvas(tempTextBitmap);
textCanvas.drawColor(selectedColor);
textCanvas.save();
textCanvas.restore();
}
canvas.drawBitmap(tempTextBitmap, matrix, new Paint());
canvas.save();
canvas.restore();
return fullTextBitmap;
}
请分别在textView或imageView上注册onclick事件来监听它们的触摸。
正如@pskink 所建议的那样,我使用了:
Matrix#mapPointes
但我用它来撤消用户触摸输入并将其与 none-rotated
位图进行比较。
例如这是我的图片
我知道文本的高度和宽度以及它旋转了多少(角度)我也知道文本的左上角在哪里,如果它没有旋转例如:
我也知道文本围绕其旋转的文本中心的位置,并且该位置在旋转过程中不会改变
现在我需要知道用户是否点击了图像,它是否在文本上,如果是,我还需要知道偏移量
编辑
这里是负责旋转和定位文本位图的代码
public Bitmap getFullTextBitmap2(Bitmap hostBitmap) {
Bitmap tempTextBitmap = getTextBitmap(); // getting the bitmap which only contain the text and has the height and width of the text
Bitmap fullTextBitmap = hostBitmap.copy(hostBitmap.getConfig(), true);
Canvas canvas = new Canvas(fullTextBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(tilt - 180, textWidth / 2, textHeight / 2);
matrix.postTranslate(position.getLeft(), position.getTop());
if (isSelected) {
Canvas textCanvas = new Canvas(tempTextBitmap);
textCanvas.drawColor(selectedColor);
textCanvas.save();
textCanvas.restore();
}
canvas.drawBitmap(tempTextBitmap, matrix, new Paint());
canvas.save();
canvas.restore();
return fullTextBitmap;
}
请分别在textView或imageView上注册onclick事件来监听它们的触摸。
正如@pskink 所建议的那样,我使用了:
Matrix#mapPointes
但我用它来撤消用户触摸输入并将其与 none-rotated
位图进行比较。