使用 pygame 扭曲的图像 [英] Images distorted using pygame

查看:38
本文介绍了使用 pygame 扭曲的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试构建我的第一个 pygame 项目并希望导入以下地图.使用的图像:

Trying to build my first pygame project and wanted to import the following map. Used image:

我的代码是:

import pygame
pygame.init()
size = (1300, 700)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
done = False
clock = pygame.time.Clock()
map = pygame.image.load('map.jpg')
map = map.convert()
map = pygame.transform.scale(map, (466,700))
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    screen.fill((255,255,255))
    screen.blit(map, (430, 0))
    pygame.display.flip()
    clock.tick(60)
pygame.quit()

输出如下:

我也尝试将 jpg 转换为 bmp,但结果仍然相同.我无法弄清楚是什么扭曲了图像,尝试使用其他图像似乎输出的图像比原始图像稍宽.我怀疑 pygame 只是读取了错误的宽度,然后将像素放入具有该宽度的数组中.

I have also tried converting the jpg to a bmp but still the same results. I cannot figure out what is distorting the image, trying with other images it appears that the outputted images is slightly wider than the original. I suspect that pygame is just reading the width wrong and then putting the pixels into an array with that width.

任何有关解决此问题的建议将不胜感激.

Any advice on fixing this would be much appreciated.

推荐答案

在 OS X 10.11 中,SDL_image(Pygame 所基于的)中有一个错误会损坏图像.

There is a bug in SDL_image (which Pygame is based on) that corrupts images in OS X 10.11.

https://bugzilla.libsdl.org/show_bug.cgi?id=3154

目前,唯一已知的解决方法是降级到 SDL_image 1.2.10,但我无法确认.

Currently, the only known workaround is to downgrade to SDL_image 1.2.10, but I have not been able to confirm.

这篇关于使用 pygame 扭曲的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆