Search code examples
juliagtk

How i can save image from @GtkCanvas()? Gtk.jl


I am using Gtk.jl and want to save image from GtkCanvas Here is my code:

canvas = @GtkCanvas()
draw_area = GtkWindow(canvas, "Canvas", 300, 300)

How can i do this?


Solution

  • You could use Cairo to create a surface and then save it as an image. eg in your draw function for the canvas in Gtk:

    @guarded draw(can) do widget
    
        ...
        if _want_file_save_flag
            surface_buf = Gtk.cairo_surface_for(can)
            # Cairo.jl functions to write a surface to your image file go here
        end
    end