ImageFile
模块¶
这个 ImageFile
模块为图像打开和保存功能提供支持功能。
此外,它还提供了 Parser
类,可用于逐段解码图像(例如,通过网络连接接收图像时)。此类实现与标准相同的使用者接口 sgmllib 和 xmllib 模块。
示例:分析图像¶
from PIL import ImageFile
fp = open("hopper.pgm", "rb")
p = ImageFile.Parser()
while 1:
s = fp.read(1024)
if not s:
break
p.feed(s)
im = p.close()
im.save("copy.jpg")
PyDecoder
¶
-
class
PIL.ImageFile.
PyDecoder
[源代码]¶ 格式解码器的python实现。重写该类并将解码逻辑添加到 decode 方法。
见 Writing Your Own File Decoder in Python
-
decode
(buffer)[源代码]¶ 重写以执行解码过程。
- 参数
buffer -- 带有要解码的数据的bytes对象。
- 返回
(已消耗字节,错误代码)的元组。如果解码结束,则对于消耗的字节返回<0。错误代码来自'errors'`
-