Search code examples
cairopygobjectpycairo

PyGObject: cairo context to pixbuf


    width, height = max(abs(fromo.realx - to.realx),3), max(abs(fromo.realy - to.realy),3)
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    ctx.scale(width, height)
    ctx.move_to(0, 0)
    ctx.line_to(1, 1)

I have that, i want to convert the cairo context to a pixbuf so i can use it as Gtk.Image. Can I do that?


Solution

  • You can use gtk_image_set_from_surface for that:

    gtk.Image.set_from_surface(surface)
    

    or even make your image from the surface:

    gtk.Image.new_from_surface(surface)