本文介绍了无法在Kivy中查看tiff图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题
我可以使用Image()模块加载图片.但是由于某种原因,我无法将.tif文件加载到kivy中.当图像源为'..\pics\lugia.png'时,图像加载完全正常.但是,如果源是'..\pics\snorlax.tif',我只会得到那个白框和错误:

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

代码

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()

技术细节

  • 图像来自 veekun.com (任天堂的财产等).
  • 所有图像均为64 x64.我只是将其中一些导出为TIFF格式.因此图像大小不应该成为问题.
  • 我正在使用Kivy版本1.11.0rc1
  • 根据Anaconda的说法,虚拟环境正在运行Python 3.5.6
  • 我正在Windows 7上通过PyCharm运行它
  • 我的sdl2_image版本为2.0.2,版本0.根据sdl2_image页面,自1.2.5版本以来,sdl2_image已支持tiff.
  • 我有libtiff版本4.0.9
  • 将文件扩展名从".tif"更改为".tiff"
  • 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'

我对您的问题
我是在做错什么,还是Kivy不支持TIFF格式?

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

推荐答案

您需要创建正确的安装
我使用anaconda安装kivy,但对正确安装依赖项并不十分了解.因此,我必须创建一个全新的虚拟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或更高版本.另外,我还将让您明确声明要创建此环境的python安装.据我所知,没有充分的理由这样做.

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. (可选)查找为您安装python的位置.
    启动Windows命令提示符.
    C:\ Users \ H> python
    import sys, os
    os.path.dirname(sys.executable)
    C:\ Users \ H \ AppData \ Local \ Programs \ Python \ Python36
    因此,我的python安装在C:\ Users \ H \ AppData \ Local \ Programs \ Python \ Python36 \ python
  2. 为新的虚拟环境准备一个位置.
    我在主目录中创建了一个名为"venvs"的文件夹.
    C:\ Users \ H \ venvs
  3. 创建新的虚拟环境.我将其命名为"env1".
    启动Windows命令提示符.
    如果您执行了步骤1
    C:\ Users \ H> C:\Users\H\AppData\Local\Programs\Python\Python36\python -m venv C:\Users\H\venvs\env1
    如果您没有执行步骤1
    C:\ Users \ H> python -m venv C:\Users\H\venvs\env1
  4. 激活新的虚拟环境
    C:\ Users \ H> C:\Users\H\venvs\env1\Scripts\activate
  5. 安装依赖项
    (env1)C:\ Users \ H> python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
  6. 安装kivy
    (env1)C:\ Users \ H> python -m pip install kivy==1.11.1
  7. PyCharm
    如果您使用的是PyCharm,请转到文件">设置"
    从设置菜单项目">项目解释器"
    点击齿轮>添加
    在添加Python解释器"菜单中,选择现有环境",然后将解释器设置为新虚拟环境的位置.
    我的位置是C:\ Users \ H \ venvs \ env1 \ Scripts \ python.exe.
    单击确定".在设置菜单中点击应用".一切正常后,您的脚本应该可以查看TIFF文件.
  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 atC:\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.

这篇关于无法在Kivy中查看tiff图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:41