making GtkImage from an array
I'm new to both Julia and GTK and I can not find in the documentation how to create a GtkImage from an array.
To create an image from a file I do :
gtkimg = Gtk.GtkImage("filename");
I have an array representing an image and I would like to do
gtkimg = Gtk.GtkImage(array);
But it yields me a MethodError on GtkImageLeaf
I have not used GtkImage so far. What I usually do is to draw to a canvas
http://juliagraphics.github.io/Gtk.jl/latest/manual/canvas.html
And starting from there you can use what Cairo.jl does offer.
From the docs it look like you need to put the data in a GdkPixbuf . Looking at the sources we do have a constructor for GdkPixbuf that takes a matrix of colors (from the package Colors).
Otherwise GtkReactive has an example of an image viewer (with interactive zoom) that uses a canvas I think:
https://github.com/JuliaGizmos/GtkReactive.jl/blob/master/examples/imageviewer.jl
Thanks for your responses !
@tknopp, It took me a little bit time, but I manage to do it with Cairo :
Cairo.image(ctx, img32, 0, 0, w, h)
@jonathanBieler, I have seen the GdkPixbuf in the Gtk docs, but did not understand how to do it in Julia.
The GtkReactive package seems to do the job well ! I will try to look deeper into it and I hope it can scale well. Otherwise, I will maybe write the Gtk part in C and make it dialog with Julia, but if I could avoid this without too many sacrifices, it would be fine !
Here's a test that does this: https://github.com/JuliaGraphics/Gtk.jl/blob/7d90e89497eba88ebf6d80274a5828e8702ececc/test/gui.jl#L297-L305
You can write the pixbuf directly to update it, the only key point you need to remember is to force it to re-render afterwards. The easiest way to do that is just to set the image property of the pixbuf to the pixbuf again (basically, a no-op with a side-effect of marking the display region dirty).