我有以下代码,改编自在线旋转文本示例。该代码工作正常,因为它将文本旋转到正确的角度,但我想知道是否有办法提高旋转文本的准确性和清晰度。在我的显示器上,旋转的文本看起来像是“阶梯状”而不是平滑的。
PFont f;
String message = "abcdefghijklmnopqrstuvwxyz";
float theta, x;
void setup() {
size(800, 200);
f = createFont("Arial",20,true);
}
void draw() {
// background(255);
fill(0);
textFont(f); // Set the font
translate(x,height/2); // Translate to the center
rotate(theta); // Rotate by theta
textAlign(LEFT);
text(message,0,0);
theta += 0.1; // Increase rotation
x += textWidth(message);
if (x>800){noLoop(); }
}
我已经通过示例进行了修改以帮助显示差异。在新代码中,我将文本更改为一串下划线,并用红色绘制了一条引用线。如果它在您的机器上运行相同,您应该会在由下划线创建的黑线中看到一条惊人的线。
String message = "________";
float theta, x;
PFont f;
void setup() {
size(800, 200);
f = loadFont("ArialMT-20.vlw");
smooth();
}
void draw() {
fill(0);
textFont(f); // Set the font
translate(x,height/2); // Translate to the center
rotate(theta); // Rotate by theta
text(message,0,0);
stroke(255,0,0);
strokeWeight(2);
line(0,0,textWidth(message),0);
theta += 0.1; // Increase rotation
x += textWidth(message);
if (x>800){noLoop(); }
}
对我来说它给出了以下输出,但我知道如果在 Mac 上运行会有所不同:
最佳答案
尝试调整 RenderingHints
:
- 设置fractional metrics至 on
- 设置text antialiasing至 on或与您的显示器匹配的子像素设置
- 设置stroke control至 pure
关于java - 改进旋转文本的显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12492505/