# Display an RGB array with Gtk.jl

**URL:** <https://discourse.julialang.org/t/display-an-rgb-array-with-gtk-jl/46506>\
**Category:** Visualization\
**Tags:** question, package, images, graphics, guis\
**Created:** [September 12, 2020, 12:29pm UTC](https://discourse.julialang.org/t/display-an-rgb-array-with-gtk-jl/46506 "2020-09-12T12:29:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![noroskir](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@noroskir](https://discourse.julialang.org/u/noroskir)\
**Post date:** [September 12, 2020, 12:29pm UTC](https://discourse.julialang.org/t/display-an-rgb-array-with-gtk-jl/46506/1 "2020-09-12T12:29:41Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [September 12, 2020, 12:45pm UTC](https://discourse.julialang.org/t/display-an-rgb-array-with-gtk-jl/46506/2 "2020-09-12T12:45:44Z")

</div>

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](https://juliagizmos.github.io/GtkReactive.jl/stable/zoom_pan.html)

---

<div class="post-metadata">

**Author:** ![noroskir](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@noroskir](https://discourse.julialang.org/u/noroskir)\
**Post date:** [September 12, 2020, 3:12pm UTC](https://discourse.julialang.org/t/display-an-rgb-array-with-gtk-jl/46506/3 "2020-09-12T15:12:33Z")

</div>

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.

```julia
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)

```
