【问题标题】:How to render non-anti-aliased font to internal image?如何将非抗锯齿字体渲染到内部图像?
【发布时间】:2011-08-10 12:04:37
【问题描述】:

使用 Python 将非抗锯齿字体(例如 ttf 字体)渲染到内部图像(例如 PIL.Image,即我不需要显示它)的最快速和准确的方法是什么?我说准确是因为我不久前用 pygame 尝试过,我给它的大小渲染的字体与 Word 或 Paint 中渲染的窗口不匹配。

【问题讨论】:

    标签: python image fonts render truetype


    【解决方案1】:

    Python Imaging Library (PIL) 可以将文本呈现为图像——我不知道它是不准确的,但我还没有完全测试它...

    来自预先存在的问题的示例:

    from PIL import Image
    from PIL import ImageFont, ImageDraw
    
    image = Image.new("RGBA", (288,432), (255,255,255))
    usr_font = ImageFont.truetype("resources/HelveticaNeueLight.ttf", 25)
    d_usr = ImageDraw.Draw(image)
    d_usr.fontmode = "1" # this apparently sets (anti)aliasing.  See link below.
    d_usr.text((105,280), "MYTEXT",(0,0,0), font=usr_font)
    

    另见:

    http://www.pythonware.com/products/pil/

    http://mail.python.org/pipermail/image-sig/2005-August/003497.html

    Python Imaging Library - Text rendering

    【讨论】:

    • 啊这个不准确正是我的意思。但我已经发布了另一个关于它的问题here
    • 啊,这实际上将其呈现为抗锯齿,我希望它不是。关于如何做到这一点的任何提示?
    • @Claudiu 根据此页面编辑了答案:mail.python.org/pipermail/image-sig/2005-August/003497.html
    • 不错!这确实使它没有抗锯齿。它仍然与记事本不同,所以 =( 对我来说,但从我问的另一个问题来看,没有办法让 PIL 做到这一点
    【解决方案2】:

    this is how it's done... 应该呈现与 windows at is 使用其算法相同的渲染。

    【讨论】:

      猜你喜欢
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 2014-05-30
      • 2012-06-17
      相关资源
      最近更新 更多