Cannot view tiff images in Kivy

时光毁灭记忆、已成空白 提交于 2019-12-10 20:06:24

问题


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 '..\pics\lugia.png', the image loads perfectly fine. But if the source is '..\pics\snorlax.tif', I just get that white box and the error:

[WARNING] [Image       ] Unable to load image <C:\Users\path\pics\snorlax.tif>
[ERROR  ] [Image       ] Error loading texture ..\pics\snorlax.tif

code

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='..\pics\lugia.png')
        self.picture = Image(allow_stretch=True, source='..\pics\snorlax.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()

technical details

  • The images are from veekun.com (property of nintendo etc).
  • All the images are 64 x 64. I just exported some of them into TIFF format. So image size shouldn't be the problem.
  • I am using Kivy version 1.11.0rc1
  • According to Anaconda, the virtual environment is running Python 3.5.6
  • I am running this via PyCharm on Windows 7
  • I have sdl2_image version 2.0.2 build 0. According to the sdl2_image page, sdl2_image has supported tiff since version 1.2.5.
  • I have libtiff version 4.0.9
  • changing the file extension from '.tif' to '.tiff'

my question to you
Am I doing something wrong, or does Kivy just not support TIFF format?


回答1:


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.

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

  1. (optional) find where python is installed for you.
    Start windows command prompt.
    C:\Users\H>python
    import sys, os
    os.path.dirname(sys.executable)
    C:\Users\H\AppData\Local\Programs\Python\Python36
    therefore, my python installation is at C:\Users\H\AppData\Local\Programs\Python\Python36\python
  2. Prepare a place for your new virtual environment.
    I created a folder called "venvs" in my home directory.
    C:\Users\H\venvs
  3. Create new virtual environment. I'll name mine "env1".
    Start windows command prompt.
    if you did step 1
    C:\Users\H>C:\Users\H\AppData\Local\Programs\Python\Python36\python -m venv C:\Users\H\venvs\env1
    if you did not do step 1
    C:\Users\H>python -m venv C:\Users\H\venvs\env1
  4. Activate the new virtual environment
    C:\Users\H>C:\Users\H\venvs\env1\Scripts\activate
  5. Install dependencies
    (env1) C:\Users\H>python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
  6. Install kivy
    (env1) C:\Users\H>python -m pip install kivy==1.11.1
  7. PyCharm
    If you're using PyCharm, go to File>Settings
    From the settings menu Project>Project Interpreter
    Click the gear>Add
    In the Add Python Interpreter menu select 'Existing environment', then set the interpreter to the location of your new virtual environment.
    Mine was C:\Users\H\venvs\env1\Scripts\python.exe.
    Click Okay. Hit Apply in the settings menu. Once you hit okay, your script should be able to view TIFF files.


来源:https://stackoverflow.com/questions/58044378/cannot-view-tiff-images-in-kivy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!