保存图片 Python
Saving a picture in Python
在Python中,我使用Python中的"makeEmpyPicture"函数创建了一张图片。如何将其保存为外部文件。我有一个字符串,我想调用它。我想要做的就是能够在不将任何库导入我的代码的情况下保存它。
试试这个功能:
def savePict(pict, name):
filehandle=getMediaPath(name)
writePictureTo(pict,filehandle)
编辑:
我猜你建议的最后一行应该是:
writePictureTo(pict,file)
而不是
writePictureTo(pict,filename).
否则变量文件不会被使用
我猜 Rob 的建议是:
- 文件名='myPicture.png'
- file=你的保存目录
然后,函数 getMediaPath(filename) 将如下所示:
getMediaPath(filename):
temp_dir = os.path.join(os.getcwd(),"../../YourCurrentFolder")
saving_dir = temp_dir + '/' + filename
return saving_dir
在Python中,我使用Python中的"makeEmpyPicture"函数创建了一张图片。如何将其保存为外部文件。我有一个字符串,我想调用它。我想要做的就是能够在不将任何库导入我的代码的情况下保存它。
试试这个功能:
def savePict(pict, name):
filehandle=getMediaPath(name)
writePictureTo(pict,filehandle)
编辑:
我猜你建议的最后一行应该是:
writePictureTo(pict,file)
而不是
writePictureTo(pict,filename).
否则变量文件不会被使用
我猜 Rob 的建议是:
- 文件名='myPicture.png'
- file=你的保存目录
然后,函数 getMediaPath(filename) 将如下所示:
getMediaPath(filename):
temp_dir = os.path.join(os.getcwd(),"../../YourCurrentFolder")
saving_dir = temp_dir + '/' + filename
return saving_dir