.gif 图像作为源代码在 Windows kivy 程序中运行良好.通过 kivy Launcher 运行显示 gif 图像的背景 [英] .gif Image as source runs nicely in Windows kivy program . Running via kivy Launcher shows background of gif image

查看:7

问题描述

我正在运行一个程序,我在小部件中显示一个 .gif 图像,它运行良好但是当我使用 kivy 启动器运行这个应用程序时,即使图像没有背景,.gif 图像也会带有一个方形框.

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 .

任何人都有任何想法,为什么这在 android 和 windows 上表现不同.

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

请参阅下面的 .kv 代码作为我如何使用 .gif 图像的示例.我将此 .gif 图像用作按钮.

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

...

推荐答案

首先确保你打包了 pil/pillow [只需将它添加到构建 apk 的要求之一] 用于 gif 加载,否则是一个纯 python 加载器使用android会很慢,第二请详细说明您所说的方框是什么意思?

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?

更新:您更新后的示例显示您正在使用 AsyncImage 与本地源,Async Image 是要与远程 url 一起用于本地源您可以只使用 Image 类.

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.

更新 3:如前所述,问题在于使用 pil 的 gif 图像加载器.并非所有图像都可以使用它.它适用于您的桌面,因为没有安装 pil,而是使用纯 python gif 加载器.由于速度问题,此加载程序无法在 android 上使用.

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.

一种解决方法是使用 gimp 打开并保存图像.那么它应该可以正常工作.另一种方法是贡献和修复:使用 pil 用于 gif 的加载器......(我必须警告网络上有很多不同的 gif,每个都有自己的细微变化.确保一个作品会导致其他作品被破坏.)

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.

在使用 gif 制作动画时可能会出现许多工件,我建议您在 .zip 中使用 images(png/jpg...) 并将其设置为源代码.这样您就可以摆脱伪影了.

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.

请确保 Image 类提供的 gif 或 .zip 动画仅用于不需要大量控制动画的情况.就像不会改变的静态动画一样.

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.

如果您的动画需要超出此范围,那么您应该通过在 Atlas 中加载精灵表来手动管理动画.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆