# How to add image to Gtk?

**URL:** https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006
**Category:** New to Julia
**Tags:** guis
**Created:** [December 26, 2017, 8:44pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006 "2017-12-26T20:44:44Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Ash\_S](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Ash\_S](https://discourse.julialang.org/u/Ash_S)
#### Post date: [December 26, 2017, 8:44pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/1 "2017-12-26T20:44:44Z")

</div>

Hello,

I am trying to add an image into a GUI using Gtk with Glade. Does anyone know how to do that or have a good website I can look at for help? I wasn’t able to find anything for Julia so I was wondering if anyone knows here. Thanks in advance!

---

<div class="post-metadata">

### Author: ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)
#### Post date: [December 26, 2017, 8:54pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/2 "2017-12-26T20:54:56Z")

</div>

Hi, you want to draw an image right?

So first you have to load the image into a 2D array. Then you can create a Canvas which is discussed here:

[http://juliagraphics.github.io/Gtk.jl/latest/manual/canvas.html](http://juliagraphics.github.io/Gtk.jl/latest/manual/canvas.html)

Then you can `copy!` the matrix into the Cairo context (i.e. `copy!(ctx, my_image)`). I am not exactly sure at the moment but when I do this the element type of the matrix is `RGB{N0f8}`. So the image is already colorized and available in RGB colors. When you load the image it might be the case that its already in this format.

---

<div class="post-metadata">

### Author: ![Ash\_S](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Ash\_S](https://discourse.julialang.org/u/Ash_S)
#### Post date: [December 26, 2017, 9:18pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/3 "2017-12-26T21:18:10Z")

</div>

I want to put in an image such as a picture from google onto the GUI

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [December 26, 2017, 10:03pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/4 "2017-12-26T22:03:33Z")

</div>

[Here](https://github.com/JuliaGraphics/Gtk.jl/issues/249) it is explained, the simplest way should be with `GtkImage`, @tobias.knopp 's method also works but is a bit more complicated if you start with say a PNG.

---

<div class="post-metadata">

### Author: ![Ash\_S](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Ash\_S](https://discourse.julialang.org/u/Ash_S)
#### Post date: [December 28, 2017, 7:13pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/5 "2017-12-28T19:13:37Z")

</div>

I tried following this example in the link you sent:

 ![example](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f90fa7e9c8b2f509063bc81941f6434ced25fa4.png)

and did this:

 ![error](https://global.discourse-cdn.com/julialang/original/3X/8/2/82de49b52233af257b8fa9bf1dc9b2c7a19b8bf9.png)

the image i am trying to display is the egg.jpg but I keep getting the error "invalid escape sequence.

Do you have any suggestions on what I can do to fix this error? Thanks!

---

<div class="post-metadata">

### Author: ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)
#### Post date: [December 28, 2017, 7:15pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/6 "2017-12-28T19:15:15Z")

</div>

try escaping your backslashes `"C:\\Users\\..."`

---

<div class="post-metadata">

### Author: ![Ash\_S](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Ash\_S](https://discourse.julialang.org/u/Ash_S)
#### Post date: [December 28, 2017, 7:16pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/7 "2017-12-28T19:16:55Z")

</div>

Ah! That worked! Thanks so much!

---

<div class="post-metadata">

### Author: ![Ash\_S](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@Ash\_S](https://discourse.julialang.org/u/Ash_S)
#### Post date: [December 29, 2017, 6:16pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/8 "2017-12-29T18:16:50Z")

</div>

I have another question.I’m trying to make the image fit inside the image widget now in the Glade GUI builder. Any suggestions/documentation on how to do that? Thanks!

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 29, 2017, 6:25pm UTC](https://discourse.julialang.org/t/how-to-add-image-to-gtk/8006/9 "2017-12-29T18:25:40Z")

</div>

Search for “GtkImage resize”. I’d guess all solutions (in C, C++, python etc.) put a resizing mechanism into the expose method (callback) of the respective widget.
