Issue
Hi I'm trying to load my image from Pillow into Pygame using BytesIO.
from PIL import Image
import io
pilImage = Image.open('AgV6E.png')
temp_io = io.BytesIO()
pilImage.save(temp_io, format='PNG')
pygame.image.load(temp_io)
I get the following error:
pygame.image.load(temp_io) pygame.error: Unsupported image format
Strangely enough though simply saving to png works.
from PIL import Image
import io
pilImage = Image.open('AgV6E.png')
pilImage.save("test.png", format='PNG')
pygame.image.load("test.png")
Anybody know how to fix this?
Solution
Turns out I needed to run BytesIO.seek(0)
before running load to set the stream position back to zero. Here is the updated code.
from PIL import Image
import io
pilImage = Image.open('AgV6E.png')
temp_io = io.BytesIO()
pilImage.save(temp_io, format='PNG')
temp_io.seek(0)
pygame.image.load(temp_io)
seek(0)
is probably what allowed it to be read correctly as it moved the stream position back to the beginning.
Thanks to Starbuck5 letting me know the answer.
Answered By - Flare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.