pygame资源图片剪裁

Posted on 2017-12-04 14:03  #大囚长#  阅读(1035)  评论(0编辑  收藏  举报
裁剪坟墓
def cropimg(image, region):
    from cStringIO import StringIO
    img = Image.open(image)
    # region = (64, 0, 192, 95)
    cropImg = img.crop(region)
    imgBuf = StringIO(cropImg.tobytes())
    imgx = pygame.image.frombuffer(imgBuf.getvalue(), (region[2] - region[0], region[3] - region[1]), "RGBA")
    return imgx

img = r'resources/images/map.png'
region = (161, 95, 193, 129)
imgx = cropimg(img, region)
screen.blit(imgx, (200,200))