【问题标题】:how to find the position of a rotated text?如何找到旋转文本的位置?
【发布时间】: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


【解决方案1】:

请分别注册到 textView 或 imageView 上的 onclick 事件以监听他们的触摸。

【讨论】:

  • 这不是文本视图。并且包含文本的 imageView 与主大图大小相同。文本是在运行时添加的,虽然它没有旋转,但我可以与之交互,但是当它旋转时,我很难找到它的位置
【解决方案2】:

正如@pskink 建议我使用的那样:

Matrix#mapPointes

但我用它来撤消用户触摸输入并将其与none-rotated 位图进行比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    相关资源
    最近更新 更多