Basándonos en las otras respuestas, he aquí una función para leer un archivo SVG una imagen de pygame en - incluyendo la corrección de orden de los canales de color y escalado:
def pygame_svg(svg_file, scale=1):
svg = rsvg.Handle(file=svg_file)
width, height= map(svg.get_property, ("width", "height"))
width*=scale; height*=scale
data = array.array('c', chr(0) * width * height * 4)
surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32, width, height, width*4)
ctx = cairo.Context(surface)
ctx.scale(scale, scale)
svg.render_cairo(ctx)
#seemingly, cairo and pygame expect channels in a different order...
#if colors/alpha are funny, mess with the next lines
import numpy
data= numpy.fromstring(data, dtype='uint8')
data.shape= (height, width, 4)
c= data.copy()
data[::,::,0]=c[::,::,1]
data[::,::,1]=c[::,::,0]
data[::,::,2]=c[::,::,3]
data[::,::,3]=c[::,::,2]
image = pygame.image.frombuffer(data.tostring(), (width, height),"ARGB")
return image
¿Hay una respuesta/biblioteca diferente que se aplica a 2011 ? (porque ha sido hace 3 años). He visto squirtle usado para cargar mapas creados en ** inkscape **. – ninMonkey
Squirtle aún no admite gran parte de SVG afaik y hacer que funcione con PyGame probablemente también requiera algo de trabajo. Estoy buscando mucho tiempo para el soporte de dibujo SVG en Windows y 64 Bit Python y creo que tengo que darme por vencido. – Trilarion