English 中文(简体)
• 如何——通过TextOnPath(Path)从信道上抽取的纸浆中测量大小
原标题:How to -accurately- measure size in pixels of text being drawn on a canvas by drawTextOnPath()

我用TextOnPath(Path)在Canvas(Canvas)上展示一些案文,我需要了解案文的方方面面。 我知道,由多个部分、曲线等构成的道路是行不通的,但我的道路是完全横向的单一部分。 我正在利用绘画、植被图普博恩(PeopleBounds)获得一份带有我想要提取的案文内容的检索。

在我任意抽取案文时,我利用这一口号在案文上抽取一个约束箱子。

在这里,一些简化的法典反映了我目前正在做的工作:

// to keep this example simple, always at origin (0,0)
public drawBoundedText(Canvas canvas, String text, Paint paint) {
    Rect textDims = new Rect();
    paint.getTextBounds(text,0, text.length(), textDims);
    float hOffset = 0;
    float vOffset = paint.getFontMetrics().descent;  // vertically centers text 
    float startX = textDims.left;  / 0
    float startY = textDims.bottom;
    float endX = textDims.right;
    float endY = textDims.bottom;

    path.moveTo(startX, startY);
    path.lineTo(endX, endY);
    path.close();

    // draw the text
    canvas.drawTextOnPath(text, path, 0, vOffset, paint);

    // draw bounding box
    canvas.drawRect(textDims, paint);
}

结果是——但不是完美的。 如果我把第二行改为最后一行:

canvas.drawText(text, startX, startY - vOffset, paint);

然后它完美地运作。 通常,右边和底边有1-3个乳房。 错误似乎也因体积而异。 任何想法? 它使我有可能做一切事,而问题在于提炼ath(TextOnPath);案文质量在走路时非常明显下降,即使道路是横向的,很可能是因为干涉算法,或者不管其是在幕后使用。 我很惊讶地发现,大小垃圾也来自那里。

最佳回答

我找到了一种办法,解决我的特殊局势,尽管它没有真正解决原来的问题。

由于我的特殊使用案例只是沿单一部分直线的行文,我得以走一条道路,并使用Canvas.drawText()和Canvas.translate()和 canvas.rotate()。 我在走路时也看到案文的随机和模糊。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签