How do I render *parts* of a svg file?

前端 未结 5 1160
借酒劲吻你
借酒劲吻你 2021-01-01 00:30

I want to render parts of a svg file by name but for the life of me I cannot figure out how to do so (using python + gtk).

Here\'s the svg file in question: http://d

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 01:14

    Grave-digging a little bit here, but the answer by ptomato from 2010 also works now in 2019 for Gtk3 with some slight modifications. The below code will render only the 3 of diamonds svg id.

    #!/usr/bin/env python
    
    import gi
    gi.require_version('Gtk', '3.0')
    gi.require_version('Rsvg', '2.0')
    
    from gi.repository import Gtk, Rsvg
    
    svg = Rsvg.Handle.new_from_file('svg-cards.svg')
    
    pixbuf = svg.get_pixbuf_sub('#3_diamond')
    
    image = Gtk.Image()
    image.set_from_pixbuf(pixbuf)
    image.show()
    
    window = Gtk.Window()
    window.set_title("Foo")
    window.connect("destroy", Gtk.main_quit)
    window.show()
    window.add(image)
    
    Gtk.main()
    

提交回复
热议问题