I’m into a problem that I can’t really understand.
I want to “include” directly into my C code a series of icons. Using the tool gdk-pixbuf-csource (with –struct option) I produced a file that initializes a ‘const’ pixdata structure for each image.
And example of an encoded image is this:
const GdkPixdata pixdata_flipH = {
0x47646b50, /* Pixbuf magic: 'GdkP' */
24 + 479, /* header length + pixel_data length */
0x2010002, /* pixdata_type */
64, /* rowstride */
16, /* width */
16, /* height */
/* pixel_data: */
"\257\0\0\0\0\1\0\0\0\1\203\0\0\0\0\2\0\0\0\2\40J\207E\202\40J\207\377"
"\202\0\0\0\0\202\40J\207\377\2\40J\207E\40J\207\2\202\0\0\0\0\1\0\0\0"
"\2\203\0\0\0\0\4\40J\2072\40J\207\377\276\322\352\377\40J\207\377\202"
<data continues......>
"\0\0\0\0\1\40J\207\1\204\0\0\0\0\1\40J\207\3\227\0\0\0\0\1\0\0\0\3\244"
};
I want to include the icons in some buttons, so I prepared the following series of statements:
GtkWidget *icon_flipH = gtk_image_new_from_pixbuf(gdk_pixbuf_from_pixdata(&pixdata_flipH, FALSE, NULL));
GtkWidget *icon_flipV = gtk_image_new_from_pixbuf(gdk_pixbuf_from_pixdata(&pixdata_flipV, FALSE, NULL));
// and so on...
In this way I’ll add the image to the button with the function:
gtk_button_set_image(GTK_BUTTON(button_flipH), icon_flipH);
Well… The GCC compiler goes in error saying that “initializer element is not constant” at each line containing gdk_pixbuf_from_pixdata() function. I can’t figure out why, because the function needs a const structure pointer and actually my structures are declared ‘const’.
Am I forgetting something? Is it not the right way to include images into the code and create pixbufs? Any tutorial in this case?
Objects defined at file scope (like
icon_flipH) have static storage duration: their lifetime is the lifetime of the program and they are initialized before the startup of the program. You can only initialize objects with static storage duration with a constant expression (e.g.,0,10 + 32, orsizeof (int)). The result of a function call is not a constant expression.