鱼C论坛

 找回密码
 立即注册
查看: 1664|回复: 1

求助:Mac下使用Pygame不能显示png图片怎么办?

[复制链接]
发表于 2019-4-23 08:31:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 23433213@qq.com 于 2019-4-23 08:32 编辑

程序代码为课程中的示例代码,在windows系统上可以正常运行。
在mac电脑上pygame已正确安装,在运行上面的代码时会提示如下错误:
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: Interlace handling should be turned on when using png_read_image

导致图片无法显示,百度上也没有太符合的解决办法,求助大神们帮忙看看。

import pygame
import sys

# 初始化Pygame
pygame.init()

size = width, height = 600, 400
speed = [-2, 1]
bg = (255, 255, 255) # RGB

# 创建指定大小的窗口 Surface
screen = pygame.display.set_mode(size)
# 设置窗口标题
pygame.display.set_caption("初次见面,请大家多多关照!")

# 加在图片
turtle = pygame.image.load("turtle.png").convert_alpha()
# 获得图像的位置矩形
position = turtle.get_rect()


while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    # 移动图像
    position = position.move(speed)

    if position.left < 0 or position.right > width:
        # 翻转图像
        turtle = pygame.transform.flip(turtle, True, False)
        # 反方向移动
        speed[0] = -speed[0]

    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]

    # 填充背景
    screen.fill(bg)
    # 更新图像
    screen.blit(turtle, position)
    # 更新界面
    pygame.display.flip()
    # 延迟10毫秒
    pygame.time.delay(10)


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-4-23 13:30:53 | 显示全部楼层
stack overflow上有个回答你可以参考下:
I had the same problem. It seems to be some bug of older libpng versions (see http://sourceforge.net/p/libpng/bugs/165/ for detail).

It should be already fixed, but not in my current setup: win32 + python 2.7.3.

As a workaround I simply converted png-24 images to png-8 in Photoshop and message has disappeared.

把png-24转成png-8
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-29 02:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表