【问题标题】:Saving a picture in Python在 Python 中保存图片
【发布时间】:2015-08-09 13:00:45
【问题描述】:

在 Python 中,我使用 Python 中的“makeEmpyPicture”函数创建了一张图片。如何将其保存为外部文件。我有一个字符串,我想调用它。我想要做的就是能够在不将任何库导入我的代码的情况下保存它。

【问题讨论】:

    标签: python image file save jython


    【解决方案1】:

    我猜 Rob 的建议是:

    • 文件名 = 'myPicture.png'
    • file = 您的保存目录

    然后,函数 getMediaPath(filename) 将如下所示:

    getMediaPath(filename):
        temp_dir = os.path.join(os.getcwd(),"../../YourCurrentFolder")
        saving_dir = temp_dir + '/' + filename
        return saving_dir
    

    【讨论】:

      【解决方案2】:

      试试这个功能:

      def savePict(pict, name):
        filehandle=getMediaPath(name)
        writePictureTo(pict,filehandle)
      

      编辑:

      我猜你建议的最后一行应该是:

      writePictureTo(pict,file) 
      

      而不是

      writePictureTo(pict,filename).
      

      否则变量 file 不会被使用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-18
        • 2023-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-07
        相关资源
        最近更新 更多