How To Display Pil Image With Pygame?
I am trying to do some video stream from my raspberry pi over the wifi. I used pygame, because i also have to use gamepad in my project. Unfortunately I stucked on displaying recei
Solution 1:
Sloth's answer is incorrect for newer versions of Pygame. The tostring()
definition is deprecated. Here is a working variant for Python 3.6, PIL 5.1.0, Pygame 1.9.3:
raw_str = frame_1.tobytes("raw", 'RGBA')
pygame_surface = pygame.image.fromstring(raw_str, size, 'RGBA')
Solution 2:
The first argument to pygame.image.fromstring
has to be a str
.
So when frame_1
is your PIL image, convert it to a string with tostring
, and load this string with pygame.image.fromstring
.
You have to know the size of the image for this to work.
raw_str = frame_1.tostring("raw", 'RGBA')
pygame_surface = pygame.image.fromstring(raw_str, size, 'RGBA')
Post a Comment for "How To Display Pil Image With Pygame?"