0

I have checked out this answer but it does not seem to explain clearly what is happening in order to display images directly from mysql db to a kivy window directly, assuming we already have the blob data from mysql in a variable called loaded_Image.

How can we display loaded_Image into window? {Preferably using a dynamic Image Widget and not from .kv file}

Please help if you have accomplished this before.

ADIMO
  • 1,107
  • 12
  • 24
Johnn Kaita
  • 432
  • 1
  • 3
  • 13

1 Answers1

0

I figured this out to the best of my understanding

First load an image in form of blob data using normal mysql python and store in a variable, my case called image, you convert it as below to data then add data to CoreImage

image = value[9]
data = io.BytesIO(image)
img = CoreImage(data, ext="png").texture

Make sure you use this for your import

from kivy.uix.image import Image, CoreImage

Next ensure you add a default image within your project folder and call it using widget as follows

widget = Image(source = 'a.jpg')

Set the texture of widget to img, then add it to your target widget or parent

 widget.texture = img
 target.add_widget(widget)

The full working code like below:

image = value[9] #Add your data
data = io.BytesIO(image)
img = CoreImage(data, ext="png").texture
widget = Image(source = 'a.jpg')
widget.texture = img
target.add_widget(widget)
Johnn Kaita
  • 432
  • 1
  • 3
  • 13