【问题标题】:Python base64 string to PyPng without saving filePython base64字符串到PyPng而不保存文件
【发布时间】:2015-01-28 21:01:46
【问题描述】:

如何在不保存到磁盘然后打开“out.png”的情况下执行此操作?

    r = requests.get(url)
    mine,encoded =  r.json()[0]['data'].split(',') #if it is segmentation
    decoded = base64.decodestring(encoded)

    if mine == 'data:image/png;base64':
        #TODO do this from memory
        g = open("out.png", "w")
        g.write(decoded)
        g.close()            

        r = png.Reader('out.png')
        print r.read()

【问题讨论】:

    标签: python base64 pypng


    【解决方案1】:

    使用bytes 关键字

    r = png.Reader(bytes=decoded)
    

    【讨论】:

      【解决方案2】:

      base53.decodestring()返回二进制数据的字符串,根据this pagepng.Reader()可以将字符串作为输入,所以你只需要将两者链接在一起。

      【讨论】:

        猜你喜欢
        • 2016-12-03
        • 2013-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-24
        • 1970-01-01
        相关资源
        最近更新 更多