コード例 #1
0
 def recreatePackedTexture(self):
   #create list of images
   imageRects = []
   for k,v in self.imageModel.images.iteritems():
     imageRects.append(v)
   rs = RectStorage()
   rs.packRectangles(imageRects)
   outImage = PILImage.new("RGBA", rs.dimensions) 
   for ri in rs.rects:
     outImage.paste(ri.image, (ri.x, ri.y, ri.x + ri.width, ri.y + ri.height))
   qimage = PILImageToQImage(outImage)
   pixmap = QtGui.QPixmap(qimage)
   self.ui.outTexture.setPixmap(pixmap)
コード例 #2
0
imageRects = []

# load all images
for f in os.listdir(sys.argv[1]):
  if f.endswith(".png"):
    i = Image.open(sys.argv[1] + os.sep + f)
    i.load()
    i = i.convert("RGBA")
    r = Rect()
    r.image = i
    imageRects.append(r) 

# auto crop all images and set dimensions
for ri in imageRects:
  ri.image = autocrop(ri.image)
  ri.width, ri.height = ri.image.size

rs = RectStorage()
rs.packRectangles(imageRects)

# create a new image
outImage = Image.new("RGBA", rs.dimensions)

for ri in rs.rects:
  outImage.paste(ri.image, (ri.x, ri.y, ri.x + ri.width, ri.y + ri.height))

# save the image
outImage.save("texture.png")