Search code examples
androidpythonkivybuildozer

Black square when displaying an Image from android storage in Kivy


I am developing some simple app with Kivy/Python. I have some problem with displaying images which earlier were saved in android storage via Camera. Below I published a take_shot method which take a picture and save it in /storage/emulated/0/Kalkulator/ dir in android. After that the path to picture will be store in sqlite database.

def take_shot(self,name,when):
    if kiedy == 'before':
        self.before='/storage/emulated/0/Kalkulator/'+name+when+'.jpg'
        camera.take_picture(self.before,self.done(when))  
    elif kiedy == 'after':
        self.after = '/storage/emulated/0/Kalkulator/' + name + when+'.jpg'
        camera.take_picture(self.after, self.done(when))

Code below present method used to reading file where data is getting from database. When I try to display file from android storage, kivy displays only black square. When I try to display images from app directory './files/photos/irina.jpg' everything works fine.

    if str(data[5])=='Empty':
        before=Image(source='./files/photos/irina.jpg', 
              keep_ratio=True,size_hint= (1,None),height=dp(400))
    else:
        before = Image(source=str(dane[5]), keep_ratio=True,size_hint= 
                     (1,None),height=dp(400))
    if str(data[6]) == 'Empty':
        after = Image(source='./files/photos/irina.jpg', 
                   keep_ratio=True,size_hint= (1,None),height=dp(400))
    else:
        after = Image(source=str(dane[6]), keep_ratio=True,size_hint= 
                   (1,None),height=dp(400))
    photos.add_widget(before)
    photos.add_widget(after)
    self.ids.box.add_widget(photos)

Where is the problem? I don't have any errors in logs.

I saw that kivy don't display any Image with higher resolution.


Solution

  • If you sure it's about picture size, things I guess you can do:

    • Try to use kivy master branch (use kivy==master in buildozer's requirements) to build apk: bug may be fixed there

    • Try to use another image provider (set KIVY_IMAGE to pil).

    • Try to reduce image size using Pillow.

    • Report issue on project's github

    • Ask for help in kivy users support google group