【发布时间】:2016-04-05 11:56:31
【问题描述】:
例如这是我的图片
我知道文本的高度和宽度以及旋转了多少(角度)我也知道文本的左上角在哪里,如果它没有旋转例如:
我也知道文本旋转的文本中心的位置,并且该位置在旋转中不会改变
现在我需要知道用户是否点击了图像是否已经在文本上,如果是,我还需要知道偏移量
编辑
这里是负责旋转和定位文本位图的代码
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;
}
【问题讨论】:
-
所以您使用的是具有比例类型 == MATRIX 的 ImageView,对吗?所以使用
Matrix#mapPoints方法 -
是 fit_center 。用户请求的每个新文本都会导致一个新的图像视图被实例化并覆盖主图像视图。新实例化的图像视图是透明的,因此用户可以看到下面的主图像。然后在透明层上我绘制不可点击的文本..当用户点击图像主图像视图得到通知并将触摸位置发送到所有层如果任何层在该位置有任何文本,则文本被选中这一切工作正常,直到你旋转文本@pskink
-
那么文本是如何旋转的?
-
当您旋转文本时,文本是包含在另一个位图(大透明的位图)中的位图,我使用 matrix.setRotate 和 matrix.postTranslate 来定位和旋转文本@pskink
标签: android bitmap image-rotation