import sys
import os
from PIL import Image
file_root = "E:\\work\\yin\\yinn"
fileList = []
n = 0
def read_bmp_file_list(path):
for root, dirs, files in os.walk(path, topdown=False):
for file in files:
fileList.append(os.path.join(root, file))
def qie_tu(file_path):
global n
im = Image.open(file_path)
img_size = im.size
print("图片宽度和高度分别是{}".format(img_size))
x = 0
y = 0
w = 512
h = 512
for j in range(0,4):
for i in range(0,6):
print(x+w*i, y+h*j,x+w*i+w, y+h*j+h)
region = im.crop((x+w*i, y+h*j,x+w*i+w, y+h*j+h))
region.save("E:\\work\\yin\\yinn_o\\{name}.jpg".format(name=n))
n=n+1
if __name__ == '__main__':
read_bmp_file_list(file_root)
for f in fileList:
qie_tu(f)