我正在阅读“wxpython in action”,并在书中找到了一个paintwindow 演示。它使用 cpickle(*.paint) 保存其数据。我想知道如何将窗口中的数据保存为 jpg 文件,以便我可以使用标准图像查看器查看它。
书中的saveas函数:
def OnSaveAs(self, event):
file_wildcard = "Paint files(*.paint)|*.paint|All files(*.*)|*.*"
dlg = wx.FileDialog(self, "save paint as ...", os.getcwd(), style=wx.SAVE|wx.OVERWRITE_PROMPT, wildcard=file_wildcard)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
if not os.path.splitext(filename[1]):
filename += ".paint"
self.filename = filename
self.SaveFile()
self.SetTitle(self.Title + " -- " + self.filename)
dlg.Destroy()
def SaveFile(self):
if self.filename:
data = self.paint.GetLinesData()
f = open(self.filename, "w")
cPickle.dump(data, f)
f.close