Python PIL | Image.seek() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 Image
模块提供了一个同名的类,用于表示 PIL 图像。该模块还提供了许多工厂函数,包括从文件加载图像和创建新图像的函数。
Image.seek()
在这个序列文件中寻找给定的帧。如果您在序列末尾之外寻找,该方法会引发 EOFError 异常。打开序列文件时,库会自动寻找第 0 帧。
请注意,在当前版本的库中,大多数序列格式只允许您搜索下一帧。
Syntax: Image.seek(frame)
Parameters:
frame – Frame number, starting at 0.
Raises: EOFError – If the call attempts to seek beyond the end of the sequence.
使用的图像:
# importing image class from PIL package
from PIL import Image
# creating gif image object
img = Image.open(r"C:\Users\System-Pc\Desktop\time.gif")
img1 = img.tell()
print(img1)
# using seek() method
img2 = img.seek(img.tell() + 1)
img3 = img.tell()
print(img3)
img.show()
输出:
0
1
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。