无法在 Kivy 中查看 tiff 图像 [英] Cannot view tiff images in Kivy

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

问题描述

问题
我可以在 kivy 中使用 Image() 模块加载图片.但由于某种原因,我无法将 .tif 文件加载到 kivy 中.当图像源是 '..picslugia.png' 时,图像加载得非常好.但是如果源是 '..picssnorlax.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 '..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()

技术细节

  • 图片来自 veekun.com(任天堂等的财产).
  • 所有图片都是 64 x 64.我只是将其中一些导出为 TIFF 格式.所以图片大小应该不是问题.
  • 我使用的是 Kivy 版本 1.11.0rc1
  • 根据 Anaconda 的说法,虚拟环境正在运行 Python 3.5.6
  • 我在 Windows 7 上通过 PyCharm 运行它
  • 我有 sdl2_image 版本 2.0.2 build 0.根据 sdl2_image 页面,sdl2_image 从 1.2.5 版本开始支持 tiff.
  • 我有 libtiff 4.0.9 版
  • 将文件扩展名从.tif"更改为.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:UsersH>python
    导入系统、操作系统
    os.path.dirname(sys.executable)
    C:UsersHAppDataLocalProgramsPythonPython36
    因此,我的 python 安装在C:UsersHAppDataLocalProgramsPythonPython36python
  2. 为您的新虚拟环境准备一个地方.
    我在我的主目录中创建了一个名为venvs"的文件夹.
    C:UsersHvenvs
  3. 创建新的虚拟环境.我将命名我的env1".
    启动 Windows 命令提示符.
    如果您执行了第 1 步
    C:UsersH>C:UsersHAppDataLocalProgramsPythonPython36python -m venv C:UsersHvenvsenv1
    如果您没有执行第 1 步
    C:UsersH>python -m venv C:UsersHvenvsenv1
  4. 激活新的虚拟环境
    C:UsersH>C:UsersHvenvsenv1Scriptsactivate
  5. 安装依赖项
    (env1) C:UsersH>python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
  6. 安装 kivy
    (env1) C:UsersH>python -m pip install kivy==1.11.1
  7. PyCharm
    如果您使用的是 PyCharm,请转到文件>设置
    从设置菜单项目>项目解释器
    点击齿轮>添加
    在添加 Python 解释器"菜单中选择现有环境",然后将解释器设置为新虚拟环境的位置.
    我的是 C:UsersHvenvsenv1Scriptspython.exe.
    点击确定.在设置菜单中点击应用.点击 OK 后,您的脚本应该能够查看 TIFF 文件.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆