腌制保存pygame Surface(python) [英] pickle saving pygame Surface (python)

查看:102
本文介绍了腌制保存pygame Surface(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图保存一个pygame.Surface,但是它不让我出错,

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

TypeError:无法腌制Surface对象

TypeError: can't pickle Surface objects

我可以节省表面吗? 也许还有另一个模块可以保存它?

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

解释:

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

我有一些可以在其中保存Surfaces的类.

I have classes which saves in them Surfaces.

推荐答案

就像猴子说的那样:您不想腌制表面.但是,如果您真的需要保存该表面的内容,而不是使用 pygame.image.save() 函数.

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.

这篇关于腌制保存pygame Surface(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆