Python3读取显示保存SQLite3中的图片

import sqlite3
import pandas as pd
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def bytes2img(bytes_img):
    # 将bytes结果转化为字节流
    bytes_stream = BytesIO(bytes_img)
    # 读取到图片
    roiimg = Image.open(bytes_stream)
    plt.imshow(roiimg)  # 显示图片
    plt.axis('off')  # 不显示坐标轴
    plt.show()
    roiimg.show()  # 展示图片
    return
def bytes2img2(bytes_img):
    # 将bytes结果转化为字节流
    bytes_stream = BytesIO(bytes_img)
    # 读取到图片
    # Read an image from a file into an array.
    roiimg = mpimg.imread(bytes_stream)
    plt.imshow(roiimg)  # 显示图片
    plt.axis('off')  # 不显示坐标轴
    plt.show()
    return
def saveImg(bytes_img):
    f = open('image.png', 'wb')
    f.write(bytes_img)
    f.close()
    return
if __name__ == '__main__':
    conn = sqlite3.connect('drugbank.db')
    cur = conn.cursor()
    cur.execute("SELECT * FROM experiences")
    # 获取table所有字段名
    col_name_list = [tuple[0] for tuple in cur.description]
    # 所有记录列表
    record_all = cur.fetchall()
    df = pd.DataFrame(record_all, columns=col_name_list)
    bytes_img = df['图纸'][1]
    saveImg(bytes_img)

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值