Python裁剪图片,游戏大图裁小图

简单粗暴直接上代码

#-*-coding:utf-8-*-  
import Image    
import sys    
import os.path    
from  datetime  import  *      
import random    
import time    
from PIL import Image

IMAGE_PATH = "F:/Map/map_001.png"  
  
xIndex = 0  
yIndex = 0  
cropSize = 512  
xNum = 0  
yNum = 0  
    
im = Image.open(IMAGE_PATH) #打开图片句柄    
pSize = im.size  
  
xNum = pSize[0]/cropSize  
yNum = pSize[1]/cropSize  
  
print "size  " ,xNum,'  ',yNum  
  
for yIndex in range(yNum):  
    for xIndex in range(xNum):  
        print "pic : " , xIndex , "_" , yIndex  
        box = (xIndex*cropSize,yIndex*cropSize,(xIndex+1)*cropSize,(yIndex+1)*cropSize) #设定裁剪区域    
        region = im.crop(box)  #裁剪图片,并获取句柄region           
        name = "F:/Map/result/map%s_%s.png" % (xIndex,yNum-1-yIndex)  
        region.save(name) #保存图片    
        # xIndex = xIndex+1  
        # yIndex = yIndex+1  
        print int(time.time());
  

 

posted @ 2017-05-04 11:11  绿萝小新  阅读(1307)  评论(0)    收藏  举报