图像“模式"列表 [英] List of Image "modes"

查看:25
本文介绍了图像“模式"列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看 PIL(与这个问题相关),我在哪里可以获得图像模式的完整列表?我看到RGB"、RGBX",我的代码以某种方式有BGRX",即使我能看到的 PIL 文档中没有提到它.例如,当与 Windows API 调用交互时,我如何查看哪个是哪个、PIL 支持什么以及选择哪些适当的模式?

Looking through PIL (and related to this question), where can I get a comprehensive list of Image modes? I see "RGB", "RGBX", my code has "BGRX" somehow even though it's not mentioned in the PIL docs that I can see. How can I see which is which, what PIL supports, and what proper modes to select when interacting with windows API calls, for example?

基本上,我对图像模式知之甚少,我想了解的不仅仅是要放入哪些字母以使其神奇地工作.

Basically I know very little about image modes and would like to learn more than just what letters to put in to make it magically work.

推荐答案

Pillow 中有两个截然不同的概念,它们的名称很相似:

There are two distinct concepts in Pillow, with confusingly similar names:

这些列在 https://pillow.readthedocs.io/en/latest/handbook/concepts.html#modes.

根据这些文档:

图像的模式定义了图像中像素的类型和深度.

The mode of an image defines the type and depth of a pixel in the image.

这种模式"是通过Image.mode属性暴露出来的,可以通过.convert()来改变code> 方法,并且可以传递给采用 mode 参数的方法.它们与原始模式"不同.

This kind of "mode" is what is exposed through an Image's .mode attribute, can be changed through the .convert() method, and can be passed to methods that take a mode parameter. They are not the same as "raw modes".

这些由 原始解码器,它将图像文件中的未压缩数据转换为 PIL Image 对象可以理解的格式.原始模式"比模式"多几倍,它们不仅传达有关图像中像素的类型(彩色或灰度)和位深度的信息,还传达有关它们在文件中的布局的信息.例如,原始模式 RGB;L 被记录为表示 24 位真彩色,行交错(首先是所有红色像素,然后是所有绿色像素,最后是所有蓝色像素)."

These are used internally by the raw decoder, which converts uncompressed data from an image file into a format that a PIL Image object can understand. There are several times more "raw modes" than "modes", and they convey information about not only the type (colored or grayscale) and bit depth of pixels in an image, but also their layout in the file. For example, raw mode RGB;L is documented as meaning "24-bit true colour, line interleaved (first all red pixels, then all green pixels, finally all blue pixels)."

如上面链接的文档中所述(以及旧的 PIL 文档),可以在 Unpack.c 中找到原始模式列表.您会在文件末尾附近找到该列表.

As noted in the docs linked above (and also in the old PIL documentation), a list of raw modes can be found in Unpack.c. You'll find the list near the end of the file.

Unpack.c 来自 Pillow 当前主分支:https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Unpack.c

Unpack.c from the current master branch of Pillow: https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Unpack.c

Unpack.c 来自 PIL 的最终版本:http://svn.effbot.org/public/tags/pil-1.1.7/libImaging/Unpack.c

Unpack.c from the final release of PIL: http://svn.effbot.org/public/tags/pil-1.1.7/libImaging/Unpack.c

这篇关于图像“模式"列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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