The code retrieves the image data and prints, STEP 2 section of the code throws UnicodeDecodeError
. In STEP 3, the retrieved image has to be displayed on the kivy coreimage widget.
def populate_fields(self, instance): # NEW
# Code retrieves text data and display in textinput fields here.
.....
.......
# STEP 1: RETRIEVE IMAGE
connection = sqlite3.connect("demo.db")
with connection:
cursor = connection.cursor()
cursor.execute("SELECT UserImage from Users where
UserID=?",self.data_items[columns[0]]['text'] )
image = cursor.fetchone()
print(image[0])
# Retrieve operation works as a image byte stream is printed as output.
# STEP 2: CONVERT BLOB TO COREIMAGE
image_loci = image[0]
data = io.BytesIO(open(image_loci, 'rb').read())
#image opened in binary mode
im = CoreImage(data, ext="png")
#STEP 3: SET OUTPUT TO IMAGE WIDGET
self.image.source = im
Database: Sqlite3
Table name: Users
Columns: UserID, UserName, UserImage
OS : Windows
TRACEBACK ERROR:
data = io.BytesIO(open(image_loci, 'rb').read()) #image opened in binary mode UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
I'm unable to understand the cause of this error. Appreciate any help and look forward to your inputs.