[英]decoding a base64 encoded image into the orignal image in python
我從遠程數據庫中提取了一個base64編碼的圖像字符串,並嘗試使用base64.decode()對其進行解碼,但是輸出圖像是損壞的圖像(圖像大小僅為幾個字節甚至0字節),代碼為:
import pymssql
import base64
import os
con=pymssql.connect(user='**',
password='**',
database='**',
host='**')
cur=con.cursor()
cur.execute("SELECT PHOTOGRAPH_IMG FROM IHHL_DETAIL_IMG WHERE APPLICATION_ID='**';")
result=cur.fetchall() #tried fetchone() too
result=list(result) #to save the tuple returned as a list
print result[0]
cur.close()
con.close()
#I've tried various formats to decode, none work
#fh=open("img.jpeg","wb")
#fh.write(result[0].decode('base64'))
with open("imageToSave.png", "wb") as fh:
fh.write(base64.decode(result[0]))
fh.close()
只需將其添加為“代碼”
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.