在字典中存储和检索图像-python [英] storing and retrieving images in dictionary - python

查看:359
本文介绍了在字典中存储和检索图像-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在字典中存储图像,以及如何根据键值从字典中检索图像.

can anyone tell me how to store images in dictionary, and how to retrieve images from the dictionary based on the key value.

提前谢谢!

推荐答案

最好将图像存储在文件中,然后使用文件名引用它们:

It is better to store images in files and then reference them with a filename:

pictures = {'mary': '001.jpg', 'bob', '002.jpg'}
filename = pictures['mary']
with open(filename. 'rb') as f:
    image = f.read()

也就是说,如果您要将图像直接存储在字典中,只需添加它们即可:

That said, if you want to store images directly in a dictionary, just add them:

pictures = {}

with open('001.jpg', 'rb') as f:
     image = f.read()
pictures['mary'] = image

图像并不特殊,它们只是数据.

Images aren't special, they are just data.

这篇关于在字典中存储和检索图像-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆