問(wèn)題描述
問(wèn)題
我可以在 kivy 中使用 Image()
模塊加載圖片.但由于某種原因,我無(wú)法將 .tif 文件加載到 kivy 中.當(dāng)圖像源是 '..picslugia.png'
時(shí),圖像加載得非常好.但是如果源是 '..picssnorlax.tif'
,我只會(huì)得到那個(gè)白框和錯(cuò)誤:
problem
I am able to load pictures with the Image()
module in kivy. But for some reason, I can't load .tif files into kivy. When the image source is '..picslugia.png'
, the image loads perfectly fine. But if the source is '..picssnorlax.tif'
, I just get that white box and the error:
[WARNING] [Image ] Unable to load image <C:Userspathpicssnorlax.tif>
[ERROR ] [Image ] Error loading texture ..picssnorlax.tif
代碼
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.image import Image
class ContainerBox(BoxLayout):
def __init__(self, **kwargs):
super(ContainerBox, self).__init__(**kwargs)
self.orientation = 'vertical'
#self.picture = Image(allow_stretch=True, source='..picslugia.png')
self.picture = Image(allow_stretch=True, source='..picssnorlax.tif')
Clock.schedule_once(lambda dt: self.add_widget(self.picture), timeout=0.1)
class SimpleImage(App):
def build(self):
return ContainerBox()
if __name__ == '__main__':
SimpleImage().run()
技術(shù)細(xì)節(jié)
- 圖片來(lái)自 veekun.com(任天堂等的財(cái)產(chǎn)).
- 所有圖片都是 64 x 64.我只是將其中一些導(dǎo)出為 TIFF 格式.所以圖片大小應(yīng)該不是問(wèn)題.
- 我使用的是 Kivy 版本 1.11.0rc1
- 根據(jù) Anaconda 的說(shuō)法,虛擬環(huán)境正在運(yùn)行 Python 3.5.6
- 我在 Windows 7 上通過(guò) PyCharm 運(yùn)行它
- 我有 sdl2_image 版本 2.0.2 build 0.根據(jù) sdl2_image 頁(yè)面,sdl2_image 從 1.2.5 版本開(kāi)始支持 tiff.
- 我有 libtiff 4.0.9 版
- 將文件擴(kuò)展名從.tif"更改為.tiff"
我的問(wèn)題
是我做錯(cuò)了什么,還是 Kivy 不支持 TIFF 格式?
my question to you
Am I doing something wrong, or does Kivy just not support TIFF format?
推薦答案
你需要?jiǎng)?chuàng)建一個(gè)正確的安裝
我使用 anaconda 來(lái)安裝 kivy,但我對(duì)正確安裝依賴(lài)項(xiàng)并不是很徹底.所以我不得不創(chuàng)建一個(gè)全新的虛擬 python 安裝.
You need to create a proper installation
I used anaconda to install kivy and I wasn't very thorough with installing the dependencies properly. So I had to create a fresh virtual python installation.
注意:這適用于 python 3.5 或更高版本.另外,我會(huì)讓你明確說(shuō)明什么 python 安裝將創(chuàng)建這個(gè)環(huán)境.據(jù)我所知,沒(méi)有充分的理由這樣做.
Note: This is for python version 3.5 or higher. Also I am going to have you explicitly state what python installation is going to be creating this environment. To my knowledge, there's no good reason to do this.
Windows
- (可選)查找為您安裝 python 的位置.
啟動(dòng) Windows 命令提示符.
C:UsersH>python
導(dǎo)入系統(tǒng)、操作系統(tǒng)
os.path.dirname(sys.executable)
C:UsersHAppDataLocalProgramsPythonPython36
因此,我的 python 安裝在C:UsersHAppDataLocalProgramsPythonPython36python - 為您的新虛擬環(huán)境準(zhǔn)備一個(gè)地方.
我在我的主目錄中創(chuàng)建了一個(gè)名為venvs"的文件夾.
C:UsersHvenvs - 創(chuàng)建新的虛擬環(huán)境.我將命名我的env1".
啟動(dòng) Windows 命令提示符.
如果您執(zhí)行了第 1 步
C:UsersH>C:UsersHAppDataLocalProgramsPythonPython36python -m venv C:UsersHvenvsenv1
如果您沒(méi)有執(zhí)行第 1 步
C:UsersH>python -m venv C:UsersHvenvsenv1
- 激活新的虛擬環(huán)境
C:UsersH>C:UsersHvenvsenv1Scriptsactivate
- 安裝依賴(lài)項(xiàng)
(env1) C:UsersH>python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
- 安裝 kivy
(env1) C:UsersH>python -m pip install kivy==1.11.1
- PyCharm
如果您使用的是 PyCharm,請(qǐng)轉(zhuǎn)到文件>設(shè)置
從設(shè)置菜單項(xiàng)目>項(xiàng)目解釋器
點(diǎn)擊齒輪>添加
在添加 Python 解釋器"菜單中選擇現(xiàn)有環(huán)境",然后將解釋器設(shè)置為新虛擬環(huán)境的位置.
我的是 C:UsersHvenvsenv1Scriptspython.exe.
點(diǎn)擊確定.在設(shè)置菜單中點(diǎn)擊應(yīng)用.點(diǎn)擊 OK 后,您的腳本應(yīng)該能夠查看 TIFF 文件.
這篇關(guān)于無(wú)法在 Kivy 中查看 tiff 圖像的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!