Display an RGB array with Gtk.jl

Hi there!

I have an image as a 3dim RGB array Array{Int32, (width, height, 3)} and I want to render it with
Gtk.jl. I have not yet found a description on how to do this.

Can anyone help ?
Thanks :slight_smile:

You can check GtkReactive, if you don’t need the interactivity I think you just need to copy the image on a canva in the draw signal.

https://juliagizmos.github.io/GtkReactive.jl/stable/zoom_pan.html

I managed to bake something together, so If anyone else needs to know:

Apperently one first has to convert the array into the Gtk.RGB type and then write the data
to a GdkPixbuf from which one can eventually create a displayable image.

using Gtk

function rgb_to_GtkImage(img_rgb::Array{UInt32})
    (x, y) = size(img_rgb)[1:2]
    data = Array{Gtk.RGB}(undef, x, y)
    for i in 1:x, j in 1:y
        data[i, j] = Gtk.RGB((img_rgb[i, j, 1]),
                             (img_rgb[i, j, 2]),
                             (img_rgb[i, j, 3]))
    end
    pixbuf = GdkPixbuf(data=data, has_alpha=false)
    return GtkImage(pixbuf)
end

# creating a red test array
img_rgb = Array{UInt32}(undef, 300, 300, 3)
img_rgb[:,:,1] .= 255
img_rgb[:,:,2] .= 0
img_rgb[:,:,3] .= 0


win = GtkWindow("RuneScape Bot", 900, 700) 
img = rgb_to_GtkImage(img_rgb)
push!(win, img)
showall(win)