我在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。数据类型为BLOB,如Oracle中describe(table)所述。
的值img
可以在这里找到
这段代码对我有用
import base64
with open("imageToSave.png", "wb") as fh:
fh.write(base64.decodebytes(img))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句