Pygame image

Solved
Neo_2014 Posted messages 38 Status Member -  
CrazyGeekMan Posted messages 971 Status Member -
Hello ????
I am busy learning the basics of pygame and displaying backgrounds and character images, but I have a problem.
There is an error when displaying an image...
It says:
Traceback (most recent call last):
File "Image name.jpg", line 16, in <module>
Character = pygame.image.load("Image name.jpg").convert()
pygame.error: Couldn’t open Image name.jpg
I really don’t understand why...
If someone could help me, thank you.</module>

2 answers

  1. CrazyGeekMan Posted messages 971 Status Member 140
     
    By "directory," I meant folder.
    When you write
    Perso = pygame.image.load(”Image Name.jpg”).convert() 

    It is equivalent to specifying the relative path:
    Perso = pygame.image.load(”./Image Name.jpg”).convert() 

    Therefore, it is necessary for your .py file to be in the same location (the same folder as your image).
    Are you coding on Windows or Linux?

    If you specify the absolute path, do you get the same error?
    The absolute path is the full path to the image, "C:\Users\neo\Image Name.jpg," for example, if you are on Windows.

    After reading the documentation, I have this information:

    Pygame may not always be built to support all image formats. At minimum, it will support uncompressed BMP. If pygame.image.get_extended() returns 'True', you should be able to load most images (including PNG, JPG, and GIF).

    So make sure that the command pygame.image.get_extended() returns true.
    1
    1. Neo_2014 Posted messages 38 Status Member 1
       
      Thank you, it worked!!!
      0
      1. CrazyGeekMan Posted messages 971 Status Member 140 > Neo_2014 Posted messages 38 Status Member
         
        Great!
        Have a good evening and take care :)
        0
  2. CrazyGeekMan Posted messages 971 Status Member 140
     
    Good evening,

    I have never used this module in Python, but have you tried specifying the absolute path to ensure that the problem does not come from your image?
    Otherwise, is the image in the same directory as your .py file?

    --
    I hope I've been helpful :)
    0
    1. Neo_2014 Posted messages 38 Status Member 1
       
      Hello and thank you for the interest you've shown in me. Although I manage fairly well with programming, I don't really know the appropriate vocabulary. For your first suggestion, whether I try in relative or absolute path, it doesn't change anything. And directory, well... I don't really know what that means....
      Thank you for your help.
      0