【发布时间】:2019-11-11 15:33:52
【问题描述】:
我在 Oracle 中有几个 blob 图像,所以我用 python 读取它们。 我可以使用我的代码正确读取和转换来自某个 table1 的图像,但是当更改为 table2 时,我无法执行相同的代码,因为我收到以下错误。
cannot identify image file <_io.BytesIO object at 0x000000000C4520A0>
这是我的代码:
import pandas as pd
import cx_Oracle
from PIL import Image
#[connection to database with connecting string `conn`]
#[query to acces 1 single image]
result = pd.read_sql(query, conn) #connection to db
img = result["IMAGE"][0].read() # reading the first BLOB result
pre_img = io.BytesIO(img)
Image.open(pre_img)
这段代码运行良好,所以唯一的问题是当我尝试从 table1 读取图像时。同样在 SQL 开发人员中,我可以预可视化 table1 中的照片,但不能使用 table2。正如 Oracle 中的 describe(table) 所说,数据类型是 BLOB。
img的值可以在here找到
【问题讨论】:
-
发布的“
img的值”是签名的 base64 编码的 1 位 Tiff 图像。所以数据本身就是一个有效的图像,似乎不是罪魁祸首。 -
你能在你的代码示例中显示任何导入语句吗?知道您将哪个库用于“图像”会很有用。图片是在寻找文件路径而不是原始数据,可能同一个库有读取原始图片的功能。
-
例如 PIL/Pillow 函数 Image.from_bytes 可能会有所帮助
-
@ypnos 你是用python看图的吗?