How do I resolve these libpng errors in pygame?

Asked

Viewed 1,186 times

2

These errors are shown when I close the game:

libpng Warning: iCCP: known incorrect sRGB profile
libpng Warning: iCCP: cHRM Chunk does not match sRGB

These mistakes happen because I’m using it:

pygame.display.set_icon(pygame.image.load("imagens/truco.png"))

How to solve this?

  • Could you include the full code in the question ? Could you provide the image . png ? Can you reproduce/isolate errors in a minimal example ?

2 answers

5


That nay are mistakes, are "warnings" (Warning) and the problem may be in the image that is with the "color profile" (ICC profile) of the image and probably does not affect your application, you can even ignore these warnings if you want, ie it is not a problem in your code.

What you can perhaps solve easily using a drawing program to fix "the image" problem, such as GIMP or Photoshop.

There is an online solution like this: http://tinypng.com - that in addition to probably solving these "warnings" will still reduce the size of the images making your program lighter in different directions.

There is also the https://pmt.sourceforge.io/pngcrush/ (download https://sourceforge.net/projects/pmt/files/pngcrush-executables/) which is able to remove invalid color profiles after installed using this command:

pngcrush -ow -rem allb -reduce file.png
  • 1

    I didn’t know this tool, solved the problem.

  • @Matheussilvapinto that good, thank you for the recognition.

3

This is about a Warning issued by libpng. Means the image file PNG that you are using possesses Chunks iCCP invalid.

To remove the Chunks invalid of an image PNG, you can use the utility convert library ImageMagick passing the argument -strip at the command line:

$ convert icone.png -strip icone_ok.png

Assuming you have an image file, in the format PNG, with dimensions of 400x400, called icone.png:

SOpt

Follows a program capable of loading the image above through the function pygame.image.load() and then use it as the icon of the window created through the function pygame.display.set_icon() without any kind of error or Warning:

import sys
import pygame

pygame.init()

icon = pygame.image.load('icone.png')
screen = pygame.display.set_mode((500, 500))

pygame.display.set_caption('FooBar')
pygame.display.set_icon(icon)
screen.blit( icon, (50,50))

clk = pygame.time.Clock()
running = True;

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False;
    pygame.display.update()
    clk.tick(25);

pygame.quit()
sys.exit()

Example being tested in a desktop Linux/GNOME:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.