問題描述
我正在運行一個程序,我在小部件中顯示一個 .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.
這篇關于.gif 圖像作為源代碼在 Windows kivy 程序中運行良好.通過 kivy Launcher 運行顯示 gif 圖像的背景的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!