【问题标题】:Disabling anti-aliasing in pygame在pygame中禁用抗锯齿
【发布时间】:2019-03-10 23:27:15
【问题描述】:

我尝试使用 pygame.PixelArray 在 pygame 中设置单个像素。不幸的是,看起来 pygame 会自动对这些像素进行抗锯齿处理。这是我迄今为止尝试过的:

import pygame


BLACK = (0, 0, 0)
BLUE  = (0, 0, 255)
WHITE = (255,255,255)


class GUI:

    def __init__(self):

        self.screen = pygame.display.set_mode((300, 300))
        pygame.mouse.set_visible(True)
        self.clock = pygame.time.Clock()

    def gameloop(self):

        running = True
        while running:
            self.screen.fill(WHITE)
            # event handling
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
            # drawing
            # for some reason, everything gets anti-aliased
            pixel_array = pygame.PixelArray(self.screen)
            pixel_array[100][100] = BLACK
            pixel_array[100][101] = BLUE
            pixel_array[101][100] = BLUE
            pixel_array[101][101] = BLACK
            del pixel_array
            # update full display
            pygame.display.flip()
            self.clock.tick(30)


def main():

    pygame.init()
    gui = GUI()
    gui.gameloop()
    pygame.quit()


if __name__ == '__main__':

    main()

我得到了什么:

我期望得到的:

系统:

Python 版本:3.7.2(64 位)
操作系统:Windows 10 家庭版 1803 Build 17134.590
pygame 版本:1.9.4
显示:集成在联想笔记本电脑 (1920 x 1080)
处理器:Intel-Core-i5-6300HQ
IGP:英特尔高清显卡 530
GPU:英伟达 GeForce GTX 960M

【问题讨论】:

  • 在 Linux 上我得到 expected 版本。您是否打开了屏幕缩放/HiDPI 显示等?
  • @Kingsley 我不知道怎么弄明白,但我当然没有更改默认设置
  • 我在 Windows 10 上也获得了预期的版本。如果您使用 screen shot of your pygame window 并在图像编辑器中查看它,是否符合您的预期?也许在不同的机器上查看图像进行比较。
  • @Eric 用pygame.image.save(self.screen, "screenshot.bmp") 截图得到了预期的结果

标签: python pygame antialiasing


【解决方案1】:

经过Eric 的提示,我发现问题不是由 pygame 引起的,而是由显示分辨率设置引起的。默认显示比例为 125%。

由于我的 Windows 设置为德语,我不知道如何描述在哪里可以找到这些英文设置,所以我做了截图:

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 2011-08-30
    • 2013-03-03
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    相关资源
    最近更新 更多