【问题标题】:Is there a way to give text a background color [closed]有没有办法给文本一个背景颜色[关闭]
【发布时间】:2023-02-10 13:24:15
【问题描述】:

有没有办法给 text() 一个背景颜色?

示例代码:

text("Hello",20,20);

我希望这段文字有背景颜色。

有人可以帮我解决这个问题吗

编辑: text() 方法在 draw()

【问题讨论】:

    标签: java text background processing


    【解决方案1】:

    一种技术是将文本放在一个矩形中,即 text(string, x,y,w,h);并使用 fill() 设置文本和背景颜色:

    color BLUE = color(64, 124, 188);
    
    PFont font;
    
    void setup() {
      size(400, 200);
      background(255);
      font = createFont("Arial", 18);
    }
    
    void draw() {
      fill(BLUE); // background color
      rect(60, 50, 300, 80);
      textSize(24);
      textAlign(CENTER, CENTER);
      fill(255); //text color
      text("Jeremiah was a bullfrog.", 60, 50, 300, 80);
    }
    
    

    【讨论】:

    • 谢谢,太客气了。但我希望它自动调整到我自己的文本大小
    • 原始帖子中没有提到自动调整大小。可能最好启动另一个线程并发布您尝试过但不起作用的源代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    相关资源
    最近更新 更多