- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我注意到在 OS X Mavericks 中使用 ImageTk.PhotoImage 的 Tkinter 应用程序中不显示 PNG 图像。但是,GIF 和 JPEG 显示良好。没有打印错误或抛出异常,调试代码显示图像已读取并且具有正确的高度和宽度。这是一个简化的示例:
import Tkinter
from PIL import Image, ImageTk
logo_file = 'test.png'
#logo_file = 'test.gif'
class Application(Tkinter.Frame):
def __init__(self, master):
Tkinter.Frame.__init__(self, master)
self.master.minsize(width=512, height=256)
self.master.config()
self.pack()
self.main_frame = Tkinter.Frame()
self.some_image = ImageTk.PhotoImage(Image.open(logo_file))
some_label = Tkinter.Label(self.main_frame, image=self.some_image)
some_label.config()
some_label.pack(side='top')
self.main_frame.place(in_=self.master, anchor='c', relx=.5, rely=.5)
root = Tkinter.Tk()
app = Application(root)
app.mainloop()
如果您使用 GIF 图像将显示,但使用 PNG 则不会。同样,这只发生在 OS X Mavericks 上,Mountain Lion 工作正常。我试过重新安装(编译 PIL),但没有成功,也尝试过新的 virtualenv。
在创建/保存 PNG 时,我是否需要正确设置某些 PNG 属性?或者这是 PIL 或 Tkinter 或 OS X 中的错误?
更新以添加一些细节
我正在使用:
这是在刚从 Mountain Lion 更新到 Mavericks 的机器上,之前安装了 PIL,我没有弄乱 Apple 提供的系统 Python。
更新 2 Pillow 设置摘要
我安装了 Pillow 2.2.1,它说它支持 PNG:
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 2.2.1
platform darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- TIFF G3/G4 (experimental) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
我还使用 brew (libpng 1.5.14) 卸载并重新安装了 libpng。然后我重新安装了 Pillow 以确保它是用它构建的,尽管我认为它使用 zlib。
尝试构建 Python 2.7.5 的更新 3
也许问题出在 zlib,试图编译 Python 2.7.5 我明白了:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
bsddb185 dbm dl
gdbm imageop linuxaudiodev
nis ossaudiodev readline
spwd sunaudiodev zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_tkinter
最佳答案
我认为你的问题是你的 PIL 是在你的 Mavericks 机器上没有 PNG 支持或者只有部分 PNG 支持的情况下构建的。
如果 PIL 无法在它想要的地方同时找到 libpng 和 libz,您将无法获得完整的 PNG 支持。在从 Mountain Lion 升级到 Mavericks 之后,这有时似乎是个问题。
这可能与您遇到的问题不同。例如,这可能归因于 Apple 再次使用有缺陷的 Tcl/Tk 版本(就像他们在 Snow Leopard 中臭名昭著的做法)。但这绝对值得一试。
与 Pillow
,以及一些老式 PIL 版本(但实际上,如果您不使用 Pillow,您几乎肯定应该使用),安装过程的末尾会为您提供一个友好的“PIL SETUP SUMMARY”部分,向您展示所有重要的配置内容。
我在本地构建的 Python 3.3.2 上使用 Pillow 2.2.1 时遇到了完全相同的问题。我使用 Homebrew 解决了它安装 libpng,然后重建 Pillow:
$ brew install libpng
$ pip-3.3 uninstall pillow
$ pip-3.3 install pillow
关于python - PIL 中的 PNG 显示在 OS X Mavericks 上损坏了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19596717/
在 python 解释器中: >>> import PIL >>> PIL.Image Traceback (most recent call last): File "", line 1, in
我在 Pillow 中遇到过这个奇怪的错误,其中导入名称 PIL 需要全部小写而不是全部大写,但我从未见过 pil在任何地方都使用小写字母。这意味着我使用的导入 PIL 的所有 python 包和文件
有没有办法使用 PIL 截取驻留在我的服务器上的指定 HTML/Javascript 页面的屏幕截图? 我想编写一个脚本来更改该 HTML 页面上的一些参数,然后让 PIL 对其进行屏幕截图。 有什么
这是我所做的描述。 我正在尝试使用 PIL 编写程序,但是在尝试导入它时(如下所示),出现错误(也如下所示)。 from PIL import Image Here is the error. Tra
我正在尝试对图像进行简单的裁剪。这是代码 from PIL.Image import Image def get_image_half(image, half="upper"): if hal
我是一名新的Python用户,也是“Stack Overflow”中的新用户,当我尝试编译 tensorflow 代码时,我遇到了一些问题,并且我无法从网站上找到答案,所以我想从这里获得一些帮助,先谢
我知道 stackoverflow 上已经有很多与此问题相关的问题,我已经阅读了所有问题,但我仍然没有成功解决此问题。我希望有人能帮我解决这个问题。 我已经安装并重新安装了 Pillow 10 次。我
我得到错误: --------------------------------------------------------------------------- ImportError
我是机器学习的初学者,所以我试图创建一个模型来识别 Keras 博客中引用的图像。我已经在 Windows 10 上安装了 Anaconda 3 以及所有软件包,如tensorflow、keras、s
我正在尝试使用过滤器 FIND_EDGES 从图片中获取边缘,它在我的 Windows PC 上工作,但是当我在我的 Raspberry Pi 上运行相同的代码时,它给出了图像模式错误的错误。 最佳答
这个问题在 Python 环境中有一些答案,但这些解决方案不适用于我的 RStudio 环境。这是我的代码: library(keras) library(tensorflow) use_condae
我正在使用 Mac OS x 10.10.3 Yosemite 和 Python 2.7.9 |Anaconda 2.2.0 (x86_64) 来处理很多 python 的东西。我正在使用 Eclip
我正在遵循这个 SageMaker 指南并使用 1.12 cpu docker 文件。 https://github.com/aws/sagemaker-tensorflow-serving-cont
`from PIL import Image, ImageDraw, ImageFont image = Image.new('RGB', (950, 250), color=(255, 255, 2
我知道如何从图片中找到边缘。但我希望轮廓边缘更厚,例如宽度 9。 from PIL import Image, ImageFilter image = Image.open('your
我有多个白色背景的 PNG 图像,并且图像的某些部分充满了图案(可能是不同的颜色,黑色、蓝色、红色、黄色等)。 如何使用 Python PIL 库将所有这些图像合并为一张图像,以便所有非白色部分出
目前我正在尝试裁剪以下地址下文件夹内的所有图像:C:\\Users\\xie\\Desktop\\tiff\\Bmp然后将它们重新保存到同一个文件夹中。下面是我试图试验的代码,两者都运行没有错误但什么
虽然它们非常相似,但我确信 Pearson 相关相似度和调整余弦相似度之间存在一些差异,因为所有的论文和网页都将它们分为两种不同的类型。 然而,它们都没有提供明确的定义。 Here是其中一页。 谁能说
这是我的forms.py: class UploadImageForm(forms.ModelForm): class Meta: model = UserImages
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我是一名优秀的程序员,十分优秀!