ImageSequence模块包括了一个wrapper类,它能够让用户迭代訪问图形序列中每一帧图像。

一、ImageSequence模块的函数

1、 
Iterator

定义:ImageSequence.Iterator(image)
⇒ Iterator instance

含义:创建一个迭代器实例,让用户循环訪问序列中的全部帧图像。

样例:见以下的样例。

二、ImageSequence模块的方法

1、 
Operator

定义:Operator []

含义:用户调用这个操作器,从0開始訪问。

当没有其它帧图像时。这个迭代器将产生一个IndexError异常。

样例:

from PIL import Image, ImageSequence

im = Image.open("D:\\Code\\Python\\test\\img\\test01.gif")

index = 1
for frame in ImageSequence.Iterator(im):
print "image: index %d, mode %s, size %s" % (index, frame.mode, frame.size)
frame.save("frame%d.png" % index)
index = index + 1 iter = ImageSequence.Iterator(im)
print "image 10: mode %s, size %s" % (iter[10].mode, iter[10].size)
iter[10].show()

图像test01.gif为多张动态图像。

通过函数ImageSequence.Iterator(im)获取了图像对象im的迭代器,然后从当中逐张取出每张图片。打印了它们的模式和尺寸。后面通过操作符[]获取迭代器中的相应图像。iter[10]相应着第十张图像。

该程序输出例如以下:

image:index 1, mode P, size (450, 450)

image:index 2, mode P, size (450, 450)

image:index 3, mode P, size (450, 450)

image:index 4, mode P, size (450, 450)

image:index 5, mode P, size (450, 450)

image:index 6, mode P, size (450, 450)

image:index 7, mode P, size (450, 450)

image:index 8, mode P, size (450, 450)

image:index 9, mode P, size (450, 450)

image:index 10, mode P, size (450, 450)

image:index 11, mode P, size (450, 450)

image:index 12, mode P, size (450, 450)

image:index 13, mode P, size (450, 450)

image:index 14, mode P, size (450, 450)

image:index 15, mode P, size (450, 450)

image:index 16, mode P, size (450, 450)

image:index 17, mode P, size (450, 450)

image:index 18, mode P, size (450, 450)

image:index 19, mode P, size (450, 450)

image:index 20, mode P, size (450, 450)

image:index 21, mode P, size (450, 450)

image:index 22, mode P, size (450, 450)

image:index 23, mode P, size (450, 450)

image10: mode P, size (450, 450)

图像test01.gif例如以下:

当中第二张图像为:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

当中第二十张图像为:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

后面通过操作符[]获取的第十张图像例如以下:

Python图像处理库PIL的ImageSequence模块介绍的更多相关文章

  1. Python图像处理库PIL的ImageStat模块介绍

    ImageStat模块用于计算整个图像或者图像的一个区域的统计数据. 一.ImageStat模块的函数 1.  Stat 定义1:ImageStat.Stat(image)⇒ Stat instanc ...

  2. python图像处理库PIL的基本概念介绍

    PIL中所涉及的基本概念有如下几个:通道(bands).模式(mode).尺寸(size).坐标系统(coordinate system).调色板(palette).信息(info)和滤波器(filt ...

  3. Python图像处理库PIL中图像格式转换(一)

    在数字图像处理中,针对不同的图像格式有其特定的处理算法. 所以,在做图像处理之前,我们须要考虑清楚自己要基于哪种格式的图像进行算法设计及事实上现.本文基于这个需求.使用python中的图像处理库PIL ...

  4. Python图像处理库PIL中图像格式转换

    o 在数字图像处理中,针对不同的图像格式有其特定的处理算法.所以,在做图像处理之前,我们需要考虑清楚自己要基于哪种格式的图像进行算法设计及其实现.本文基于这个需求,使用python中的图像处理库PIL ...

  5. Python图像处理库——PIL

    PIL全称Python Image Library,是python官方的图像处理库,包含各种图像处理模块.Pillow是PIL的一个派生分支,包含与PIL相同的功能,并且更灵活.python3.0之后 ...

  6. Python图像处理库(PIL)

    官方:(详细)http://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html http://pillow.readthedocs.io/e ...

  7. Python图像处理库PIL从入门到精通

    https://blog.csdn.net/column/details/pythonpil.html 示例: from PIL import Image import pytesseract pyt ...

  8. Python图像处理库:PIL中Image,ImageDraw等基本模块介绍

    Python图像处理库:PIL中Image,ImageDraw等基本模块介绍 标签: 图像处理PILPYTHON 2016-08-19 10:58 461人阅读 评论(0) 收藏 举报  分类: 其他 ...

  9. Python图像处理库:Pillow 初级教程

    Python图像处理库:Pillow 初级教程 2014-09-14 翻译 http://pillow.readthedocs.org/en/latest/handbook/tutorial.html ...

随机推荐

  1. Maven打包可执行Jar的几种方法

    http://m.blog.csdn.net/article/details?id=51871705

  2. servlet的编码原理

    编码问题: 在介绍编码问题前,先介绍一下java平台(JVM)上的编码转化情况.首先要说明的一点,在JVM中,即java平台上,运行的程序一定都是Unicode编码方式的.对于代码中的字符串常量,根据 ...

  3. java执行shell/cmd命令

    try { Process p =Runtime.getRuntime().exec("chmod 777 /home/bomb/MoveToy/WebRoot/a.sh " ); ...

  4. wp中的双向绑定

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...

  5. Oracle 外键约束子表、父表

    CREATE TABLE employees(     employee_id      NUMBER(6),     last_name        VARCHAR2(25) NOT NULL, ...

  6. js数组添加或删除元素

    var arr = new Array(); arr[] = "aaa"; arr[] = "bbb"; arr[] = "ccc"; ar ...

  7. 【WPF】C#代码动态改变控件的样式

    需求:C#代码生成的一组按钮Button需要设置样式. 如果是在XAML中引入样式: <!-- 引入资源 --> <UserControl.Resources> <Res ...

  8. JavaScript 使用 php 的变量

    php 里面有一个变量,我想让 js 调用他, 有如下流程: <?php for ($i = 0; $i < 8; $i++) { echo "<tr>"; ...

  9. [log]利用logrotate对Linux log进行管理

    转自:http://feikiss.iteye.com/blog/1402181 https://linux.cn/article-4126-1.html Syslog-ng服务是Linux系统中重要 ...

  10. 使用Spring MVC统一异常处理实战<转>

    1 描述 在J2EE项目的开发中,不管是对底层的数据库操作过程,还是业务层的处理过程,还是控制层的处理过程,都不可避免会遇到各种可预知的.不可预知的异常需要处理.每个过程都单独处理异常,系统的代码耦合 ...