我正在尝试通过 wifi 从我的树莓派上进行一些视频流。我使用了 pygame,因为我还必须在我的项目中使用游戏手柄。不幸的是我坚持显示收到的帧。很快:我得到 jpeg 帧,用 PIL 打开它,转换为字符串 - 之后我可以从字符串加载图像
image_stream = io.BytesIO()
...
frame_1 = Image.open(image_stream)
f = StringIO.StringIO()
frame_1.save(f, "JPEG")
data = f.getvalue()
frame = pygame.image.fromstring(frame_1,image_len,"RGB")
screen.fill(white)
screen.blit(frame, (0,0))
pygame.display.flip()
错误是:
Traceback (most recent call last):
File "C:\Users\defau_000\Desktop\server.py", line 57, in <module>
frame = pygame.image.fromstring(frame_1,image_len,"RGB")
TypeError: must be str, not instance
对于较新版本的 Pygame,Sloth 的答案是不正确的。这tostring()
定义已被弃用。这是 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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)