Retrieve image from sqlite3 and display in Kivy image widget - ValueError

后端 未结 2 490
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 19:26

REQUIREMENT

I\'m trying to retrieve an image from Database and set this image to kivy image widget, this operation throws a ValueError, unsure of the ca

相关标签:
2条回答
  • 2021-01-25 19:46

    After execution of io.BytesIO(), data is in Bytes. Use Kivy CoreImage and texture to convert data.

    Replace

    self.image.source = data
    

    with:

    self.image.texture = CoreImage(data, ext="png").texture
    

    Image source

    source
    

    Filename / source of your image.

    source is a StringProperty and defaults to None

    Output

    0 讨论(0)
  • 2021-01-25 19:51

    Ikolim's answer is good but to be more specific, If you want to display a binary image directly into kivy you can simply work with io module (import io) and kivy image module (kivy.uix.image)

    Check this code:

    from kivy.uix.image import Image, CoreImage
    import io
    
    
    binary_data= #binary img extracted from sqlite
    
    data = io.BytesIO(binary_data)
    img=CoreImage(data, ext="png").texture
    
    new_img= Image()
    new_img.texture= img
    
    0 讨论(0)
提交回复
热议问题