我正在使用 Java 框架 iText 将图像绘制为 pdf。我需要绘制指定宽度的线条。有一种方法setLineWidth(float width)
在类里面PdfContentByte
那应该改变它。然而,无论我将什么值作为参数传递,绘制的线条总是特别细。
在 setLineWidth
的 javadoc 中有如下一行:
The line width specifies the thickness of the line used to stroke a path and is measured in user space units.
我不知道什么是“空间单位”。 iText 中的所有其他内容似乎都以点(大约 1/72 英寸)为单位进行测量。我找不到任何关于这些“空间单位”是什么以及如何更改它们的引用资料。
代码:
to.setLineWidth(thickness);
to.moveTo(x, y);
to.lineTo(x + 100, y + 100);
变量 to
包含 PdfContentByte
的实例。
最佳答案
已解决。 lineTo 调用后没有调用 stroke 方法。这就是为什么它在调用 stoke 方法之前使用另一个线宽集。 正确的代码如下所示:
to.setLineWidth(thickness);
to.moveTo(x, y);
to.lineTo(x + 100, y + 100);
to.stroke();
关于java - 如何更改 iText 中的线条粗细?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2757813/