問(wèn)題描述
我正在運(yùn)行一個(gè)程序,我在小部件中顯示一個(gè) .gif 圖像,它運(yùn)行良好但是當(dāng)我使用 kivy 啟動(dòng)器運(yùn)行這個(gè)應(yīng)用程序時(shí),即使圖像沒(méi)有背景,.gif 圖像也會(huì)帶有一個(gè)方形框.
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 上表現(xiàn)不同.
Any one any ideas , why this is behaving differently on android and windows .
請(qǐng)參閱下面的 .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 [只需將它添加到構(gòu)建 apk 的要求之一] 用于 gif 加載,否則是一個(gè)純 python 加載器使用android會(huì)很慢,第二請(qǐng)?jiān)敿?xì)說(shuō)明您所說(shuō)的方框是什么意思?
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 是要與遠(yuǎn)程 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.
第二:如果你得到的是白色背景而不是圖像,那么你給了它錯(cuò)誤的路徑.確保您的圖像存在于目錄中,或者您的目錄存在于啟動(dòng)器的正確位置.
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:如前所述,問(wèn)題在于使用 pil 的 gif 圖像加載器.并非所有圖像都可以使用它.它適用于您的桌面,因?yàn)闆](méi)有安裝 pil,而是使用純 python gif 加載器.由于速度問(wèn)題,此加載程序無(wú)法在 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 打開(kāi)并保存圖像.那么它應(yīng)該可以正常工作.另一種方法是貢獻(xiàn)和修復(fù):使用 pil 用于 gif 的加載器......(我必須警告網(wǎng)絡(luò)上有很多不同的 gif,每個(gè)都有自己的細(xì)微變化.確保一個(gè)作品會(huì)導(dǎo)致其他作品被破壞.)
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.)
要在桌面上重現(xiàn)您的問(wèn)題,只需安裝枕頭.
To reproduce your issue on desktop just install pillow.
在使用 gif 制作動(dòng)畫(huà)時(shí)可能會(huì)出現(xiàn)許多工件,我建議您在 .zip
中使用 images(png/jpg...) 并將其設(shè)置為源代碼.這樣您就可以擺脫偽影了.
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.
請(qǐng)確保 Image 類提供的 gif 或 .zip 動(dòng)畫(huà)僅用于不需要大量控制動(dòng)畫(huà)的情況.就像不會(huì)改變的靜態(tài)動(dòng)畫(huà)一樣.
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.
如果您的動(dòng)畫(huà)需要超出此范圍,那么您應(yīng)該通過(guò)在 Atlas 中加載精靈表來(lái)手動(dòng)管理動(dòng)畫(huà).
If your animations needs go beyond this then you should manage your animation manually by loading a sprite sheet in a Atlas.
這篇關(guān)于.gif 圖像作為源代碼在 Windows kivy 程序中運(yùn)行良好.通過(guò) kivy Launcher 運(yùn)行顯示 gif 圖像的背景的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!