我们如何消除 pygame 图像中的模糊?

发布于 2025-01-10 02:48:39 字数 1329 浏览 1 评论 0原文


    
    import pygame as pygame , sys
    
    pygame.init()
    size = (700,500)
    window_game = pygame.display.set_mode(size)
    print(pygame.mouse.get_cursor())
    _run_ = True
    
    
    class mySprite(pygame.sprite.Sprite):
        def __init__ (self,width,height,cord_x,cord_y,color):
            super().__init__()
            self.image = pygame.Surface([width,height])
            self.image.fill(color)
            self.rect = self.image.get_rect()
            self.rect.center = [cord_x,cord_y]
#my background image
    bgimg = pygame.image.load("download.jpg")
    bgimg = pygame.transform.smoothscale(bgimg, size)
    
    placeSP = [mySprite(50,20,100,150,(10,205,120))]
    placeSP_group = pygame.sprite.Group()
    
    Clock = pygame.time.Clock()
    FPS = 240
    while _run_:
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.QUIT
                sys.exit()
            placeSP.append(mySprite(50,20,100,170,(10,25,0)))
        pygame.display.flip()
        window_game.blit(bgimg,(0,0))
        placeSP_group.draw(window_game)
        placeSP_group.add(placeSP[:])
        Clock.tick(FPS)

现在我遇到的问题是 download.jpg 是 4k 分辨率,如果我尝试将该图像放入我的窗口中,img 会非常模糊,我也尝试了更多 img,但它们都很模糊 我是否尝试获取窗口大小的图片,或者我是否必须做其他事情,请告诉我......


    
    import pygame as pygame , sys
    
    pygame.init()
    size = (700,500)
    window_game = pygame.display.set_mode(size)
    print(pygame.mouse.get_cursor())
    _run_ = True
    
    
    class mySprite(pygame.sprite.Sprite):
        def __init__ (self,width,height,cord_x,cord_y,color):
            super().__init__()
            self.image = pygame.Surface([width,height])
            self.image.fill(color)
            self.rect = self.image.get_rect()
            self.rect.center = [cord_x,cord_y]
#my background image
    bgimg = pygame.image.load("download.jpg")
    bgimg = pygame.transform.smoothscale(bgimg, size)
    
    placeSP = [mySprite(50,20,100,150,(10,205,120))]
    placeSP_group = pygame.sprite.Group()
    
    Clock = pygame.time.Clock()
    FPS = 240
    while _run_:
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.QUIT
                sys.exit()
            placeSP.append(mySprite(50,20,100,170,(10,25,0)))
        pygame.display.flip()
        window_game.blit(bgimg,(0,0))
        placeSP_group.draw(window_game)
        placeSP_group.add(placeSP[:])
        Clock.tick(FPS)

now the problem I have is that the download.jpg is 4k res and if I try to fit that image in my window the img is very blurry and i have also tried many more img but they were all blurry
do I try to get a picture of the window size or do i have to do something else pls tell me....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2025-01-17 02:48:39

你不能。您可以使用 pygame.transform.smoothscale 选择模糊图像

bgimg = pygame.transform.smoothscale(bgimg, size)

,也可以使用 pygame.transform.scale 选择锯齿图像。

bgimg = pygame.transform.scale(bgimg, size)

如果您不希望这样,则必须使用更高分辨率的图像。

You can't. You can choose between a blurred image with pygame.transform.smoothscale

bgimg = pygame.transform.smoothscale(bgimg, size)

or a jagged image with pygame.transform.scale

bgimg = pygame.transform.scale(bgimg, size)

If you don't want that, you have to use a higher resolution image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文