Python Imaging Library: ImageFile Module(图像文件模块)

Python Imaging Library: ImageFile Module(图像文件模块)

ImageFile模块为图像打开和保存功能提供了支持函数。

此外,它还提供了一个解析器类,可以被用来对图像片段进行解码(例如,当通过网络连接接收图像时)。这个类实现了与标准sgmllib和xmllib模块相同的使用者接口。

例程:解析图像

import ImageFile
fp = open("lena.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")

函数

Parser

ImageFile.Parser() ⇒ Parser instance

创建一个解析器对象。解析器不能重用。

方法

feed

parser.feed(data)

向解析器提供一串数据。这个方法可能会引起一个IOError异常。

close

parser.close() ⇒ image or None

通知解析器完成解码。如果解析器成功地解码了一个图像,它将返回一个图像对象。否则,该方法会引发一个IOError异常。

Note: If the file cannot be identified, the parser will raise an IOError exception in the close method. If the file can be identified, but not decoded (for example, if the data is damaged, or if it uses an unsupported compression method), the parser will raise an IOError exception as soon as possible, either in feed or close.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值