{"id":1335,"date":"2013-10-08T11:55:33","date_gmt":"2013-10-08T11:55:33","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=1335"},"modified":"2026-06-17T09:15:40","modified_gmt":"2026-06-17T08:15:40","slug":"images","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/gui-programming-in-c\/gtk\/images\/images","title":{"rendered":"Images"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Display Images In A fixed Container<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This example sets the main window to be a fixed container into which you can place images at specified positions<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); \t\t\/\/GTK_WINDOW_TOPLEVEL = Has a titlebar and border, managed by the window manager.\n\t\n\t\/\/Get screen size\n\tint ScreenWidth;\n\tint ScreenHeight;\n\tGdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(MainWindow));\n\tScreenWidth = gdk_screen_get_width(screen);\t\t\t\/\/ in pixels\n\tScreenHeight = gdk_screen_get_height(screen);\n\t\n\t\/\/Create a Fixed Container\n\tGtkWidget *fixed;\n\tfixed = gtk_fixed_new();\n\tgtk_widget_set_size_request(fixed, ScreenWidth, ScreenHeight);\n\tgtk_container_add(GTK_CONTAINER(MainWindow), fixed);\n\tgtk_widget_show(fixed);\n\n\t\/\/Add an image\n\tGtkWidget *image;\t\t\t\n\timage = gtk_image_new_from_file(\"\/home\/pi\/projects\/my_project\/images\/my_image.png\");\n\tgtk_fixed_put(GTK_FIXED (fixed), image, 10, 20);\t\t\/\/x, y from top left\n\t\n\t\n\tgtk_widget_show_all(MainWindow);\n\t<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Change an image<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tgtk_image_set_from_file(GTK_IMAGE(image), \"\/home\/pi\/projects\/my_project\/images\/my_image2.png\");<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Clear an image<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tgtk_image_clear(GTK_IMAGE(imgDialSequence));<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Delete an image<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tgtk_widget_destroy(imgDialSequence);\n\timgDialSequence = NULL;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can safely used destroy on a widget that hasn&#8217;t actually been displayed yet. &nbsp;You can re-create and place&nbsp;the widget again later after it has&nbsp;previously been destroyed, you&#8217;re just removing its current usage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Paths<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The path you specify is not the path referenced from the executable, it must be the actual path to the image as otherwise the image won&#8217;t be shown when running your executable&nbsp;by specifying its path from another location.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display Images In A fixed Container This example sets the main window to be a fixed container into which you can place images at specified positions Change an image Clear an image Delete an image You can safely used destroy on a widget that hasn&#8217;t actually been displayed yet. &nbsp;You can re-create and place&nbsp;the widget [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[108],"tags":[],"class_list":["post-1335","post","type-post","status-publish","format-standard","hentry","category-images"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=1335"}],"version-history":[{"count":9,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1335\/revisions"}],"predecessor-version":[{"id":3167,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1335\/revisions\/3167"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=1335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=1335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=1335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}