【问题标题】:Python, How to render Text Emoji with Pygame? [duplicate]Python,如何使用 Pygame 渲染文本表情符号?
【发布时间】:2018-03-21 08:46:38
【问题描述】:

如何在 python 3.6 中使用 pygame(font.render(), font.freetype/font.font) 在字符串中渲染表情符号?如果不再可能,我需要在 Pillow Draw.text() 中渲染代码。我会很感激。 放弃这个:(填写这个什么都没有的问题,因为看起来我的帖子主要是代码,所以我添加了一些什么来启用帖子)

# -*- coding: UTF-8 -*-

import pygame, emoji
import pygame.freetype

pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
done = False

pygame.font.init()
font = pygame.freetype.SysFont("segoe-ui-symbol.ttf", size=50)
#font = pygame.font.SysFont("segoe-ui-symbol.ttf", 72)
font_color = (255,255,255, 255)
font_background = (0,0,0, 0)

text_string = emoji.emojize('????')
#text_string = u'ujiHelloÁpQ|, World ????????'
#text_string = u'ujiHelloÁpQ|\U0001f44d, World ????'
#print(emoji.emojize('Python is :thumbs_up_sign:'))
#text = font.render("♛", True, font_color, (0,0))
#text = font.render(text_string, True, font_color, (0,0))
text = font.render(text_string, fgcolor=font_color, size=0)

image_size = list(text[0].get_size())
text_image = pygame.Surface(image_size)
text_image.fill(font_background)
pygame.display.flip()

text_image.blit(text[0], (0,0))

#print(dir(text_image))

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            done = True

    screen.fill((0, 0, 0))
    #screen.blit(text,
    screen.blit(text_image,
        (320 - text[0].get_width() // 2, 240 - text[0].get_height() // 2))

    pygame.display.flip()
    clock.tick(60)

【问题讨论】:

    标签: python text pygame render emoji


    【解决方案1】:

    我在这里看到两个可能的问题。

    首先,如果没有任何显示或应用程序似乎停止运行,则 Pygame 找不到 SysFont。这发生在 Mac 上,因为没有 segoe-ui-symbol.ttf 作为系统字体。因此,我下载了一个version from the internet 并从中创建了一个普通的freetype.Font

    效果很好。

    第二个问题可能是字体本身没有这些字符。有时操作系统会将字体无法呈现的字符替换为不同的字体。

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 2020-02-26
      • 2013-06-25
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 2014-07-27
      相关资源
      最近更新 更多