pickle saving pygame Surface (python)

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

I tried to save a pygame.Surface but it doesn't let me, error

TypeError: can't pickle Surface objects

I can make it save surfaces? Or maybe there is another module that can save it ?

EXPLANATION:

a = pygame.Surface( (5,5) ) file = open("hello", "w") pickle.dump(a, file) 

I have classes which saves in them Surfaces.

回答1:

As monkey said: You don't want to pickle a surface. But if you really need to save that surfaces' content than use the pygame.image.save() function.

If you prefer your surface not to be an actual image file (for whatever reason) you could use the pygame.image.tostring() function which lets you convert the surfaces' content into a stringbuffer.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!