def surfaceData(srf, compress=zlib.compress):
"Convert surface to bytes data with optional compression"
if not isinstance(srf, pygame.Surface): srf = srf.image
w, h = srf.get_size()
a = hasAlpha(srf)
mode = (1 if a else 0) + (2 if compress else 0)
mode = struct.pack("!3I", mode, w, h)
data = pygame.image.tostring(srf, "RGBA" if a else "RGB")
return (compress(data) if compress else data), mode
评论列表
文章目录