paarth batra
paarth batra

Reputation: 1412

.gif Image as source runs nicely in Windows kivy program . Running via kivy Launcher shows background of gif image

I am running a program where i am showing a .gif image in a widget and it works perfectly well however when i run this app using kivy launcher the .gif image comes with a square box even when the Image is without a backgrund .

Any one any ideas , why this is behaving differently on android and windows .

Please see below .kv code as an example of how i used .gif image . I am using this .gif image as a button .

<ButImage@ButtonBehavior+AsyncImage>
    canvas.before:
        Color:
            rgb: (0, 0, 1)
        PushMatrix
        Rotate:
            axis: 0,0,1
            angle: 20
            origin: self.center
    source: "images/butterflybluex.gif"
    canvas.after:
        PopMatrix

...

Attached GIF

Upvotes: 3

Views: 2371

Answers (2)

Victor Manhani
Victor Manhani

Reputation: 1

I know that this response is a little delayed, but I was having these problems recently and decided to change the access to the file with absolute path.

The reason is that the Android/Ios path manager is different from the Desktop. On the Desktop, we can use a relative path that gets the current path and the path of the image file for us, but on android/Ios, we should use the absolute path to find the path of our image or any file we want to use.

Path to files in kivy app not valid after building with buildozer

Upvotes: 0

qua-non
qua-non

Reputation: 4182

First make sure that you package pil/pillow [just add it to one of the requirements while building the apk] for gif loading, otherwise a pure python loader that is very slow for android would be used, Second please elaborate what you mean by the square box?

Update: your updated example shows that you are using AsyncImage with a local source, Async Image is ment to be used with a remote url for local sources you can just use a Image class.

Second: If you are getting a white background instead of a image you gave it the wrong path. Make sure your image is present in the directory or that your directory is present in the right place on the launcher.

Update 3: The issue as stated earlier is with gif image loader using pil. Not all images work with it. It works on your desktop cause pil isn't installed and a pure python gif loader is used instead. This loader would not be usable on android cause of speed issues.

One workaround is to use gimp to open and save the image. It should work properly then. One other way is to contribute and fix: the loader using pil for gif...(I must warn there are so many different gifs on web each with their own slightly changes. Making sure one works would lead to others getting broken.)

To reproduce your issue on desktop just install pillow.

There are many artifacts that can come up while using gifs for animation, I'd recommend you use images(png/jpg...) in a .zip and set that to the source. That way you get rid of the artifacts.

Please make sure that gif or .zip animation provided by the Image class, is only used for situations where you don't need to control the animation a lot. Like for static animations that don't change.

If your animations needs go beyond this then you should manage your animation manually by loading a sprite sheet in a Atlas.

Upvotes: 4

Related Questions