-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimgwithoutcache.py
More file actions
59 lines (46 loc) · 1.4 KB
/
imgwithoutcache.py
File metadata and controls
59 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from functools import lru_cache
from PIL import Image
class ImgCache:
def __init__(self):
self.ImageID = 0
self.ImageList = []
self.MaxID = 0
self.__tmppic = ''
def next_image_func(self, path_holder, debug=False):
"""
获取下一个缓存 如果是被删除的缓存则重新读取图片
"""
self.ImageID += 1
if self.ImageID > self.MaxID:
path = path_holder.next_path()
self.MaxID = self.ImageID
else:
path = path_holder.get_path(self.ImageID)
img = Image.open(path)
if debug:
print(path_holder.get_path(self.ImageID))
return img, path
def previous_image(self, path_holder):
"""
获取上一个缓存 如果是被删除的缓存则重新读取图片
"""
if self.ImageID == 0: # 未初始化
raise Exception('PathHolder列表为空')
if self.ImageID == 1:
path = path_holder.get_path(0)
img = Image.open(path)
else:
self.ImageID -= 1
path = path_holder.get_path(self.ImageID)
img = Image.open(path)
return img, path
@property
@lru_cache(20)
def img(self):
return self.__tmppic
@img.setter
def img(self, img):
img.load()
self.__tmppic = img
if __name__ == '__main__':
print('Done')