Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with Image.load_from_file()  (Read 4289 times)

0 Members and 1 Guest are viewing this topic.

magikmw

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problem with Image.load_from_file()
« on: October 29, 2012, 09:43:49 pm »
I'm having problems with loading a png into an Image object.
The same method works fine with Texture.

Code follows, first my call, and then the error.

# Load the icon file
icon = Image.load_from_file('game/pngs/icon.png')
window.set_icon(16,16,icon.get_pixels())

Traceback (most recent call last):
  File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "game/__main__.py", line 302, in <module>
    main()
  File "game/__main__.py", line 281, in main
    icon = Image.load_from_file('game/pngs/icon.png')
  File "sfml.pyx", line 1870, in sfml.Image.load_from_file (src/sfml.cpp:23910)
TypeError: expected bytes, str found
 

I'm thinking it's an API error or maybe I'm doing something wrong?

Edit:
Oh, and I'm using SFML 2.0 RC1, pySFML build from tar on github, and Python3.3
« Last Edit: October 29, 2012, 09:45:23 pm by magikmw »

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Re: Problem with Image.load_from_file()
« Reply #1 on: December 02, 2012, 11:31:35 pm »
I fixed it on the master branch. Until you can get an updated build, you can use the b prefix to pass a bytes string:

Code: [Select]
icon = Image.load_from_file(b'game/pngs/icon.png')
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

 

anything