我正在尝试使用更大的背景图像为游戏制作图块并对其进行裁剪,但在保存前 17 张图像后,我开始遇到问题。第 18 张图像底部变黑,其余图像全黑。有什么想法吗?
这是我的代码。图像大小=(512, 512), 瓦片大小=(32, 32)
def __init__(self, path, imagesize, tilesize):
self.tiles = dict()
self.backimage = Image.open(path)
self.backimage.resize(imagesize)
self.x = imagesize[0]/tilesize[0]
self.y = imagesize[1]/tilesize[1]
currx = 0
curry = 0
for i in range(self.x):
for j in range(self.y):
tmp = path + str(i) + "_" + str(j) + ".png"
self.tiles[(i, j)] = tmp
image = self.backimage.crop((currx, curry, currx+tilesize[0], curry+tilesize[1]))
image.save(tmp, "PNG")
curry += tilesize[1]
currx += tilesize[0]