【问题标题】:how to show image after fetching from firebase从firebase获取后如何显示图像
【发布时间】:2019-04-25 00:43:21
【问题描述】:

我正在尝试使用 python 从 firebase 存储中获取图像到我的树莓派 3 中。

    import urllib.request 
    URL=urllib.request.urlretrieve("https://firebasestorage.googleapis.com/v0/b/cameraviewer-32936.appspot.com/o/images%2F49567?alt=media&token=1eded9d0-b9f0-48bf-b869-37756b31a94a")

URL 对象有几个键值对。其中之一是“str”,其值为:

'C:\Users\DELL\AppData\Local\Temp\tmp4ki4w7we'

上面的值代表了图像获取到我的设备的路径但是我如何打开图像。我不知道该去哪里,或者我很困惑。

【问题讨论】:

    标签: python firebase raspberry-pi firebase-storage


    【解决方案1】:

    使用 Python Imaging Library (PIL) 非常简单。 PIL 是免费的开源库。

    如何安装 PIL

    如果您没有安装 PILLOW,首先打开一个 终端 ( CTRL + ALT + T ) 并使用 command 下载它:

    sudo pip install Pillow
    

    显示图像

    安装成功后,使用下面的代码显示你下载的图片:

    from PIL import Image
    import urllib.request 
    
    URL=urllib.request.urlretrieve("https://firebasestorage.googleapis.com/v0/b/cameraviewer-32936.appspot.com/o/images%2F49567?alt=media&token=1eded9d0-b9f0-48bf-b869-37756b31a94a")
    img = Image.open(URL[0])
    img.show()
    

    【讨论】:

    • 感谢您的帮助。但问题是代码第 3 行的响应有许多名称值对。一个键是“str”,其值为“C:\Users\DELL\AppData\Local\Temp\tmp4ki4w7we”。我将从不同的 URL 获取,因此 str 的值将在每次从服务器读取迭代时发生变化。您已手动将此值放入 Image.open() 中。我该如何克服这个问题?
    • 另外,我在执行上述语法时遇到以下错误: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
    • 请尝试编辑的最后一个示例,如果出现任何问题,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2017-11-24
    • 1970-01-01
    • 2017-04-24
    • 2022-10-01
    • 2020-02-01
    • 2021-12-03
    相关资源
    最近更新 更多