0

I have raw pixel data with simple boolean color (on = 1, off = 0). Essentially, a black and white image written in hex. I am trying to place this data on a GTK_IMAGE in my GUI using the following code (NOTE, c++):

GtkWidget *image
GdkPixbufLoader *loader;
const unsigned char hexData[] = {0x80, 0x00, 0x80, 0x00, etc}; //This will put evenly spaced pixels
gdk_pixbuf_loader_write(loader, hexData, strlen((char *)hexData), NULL); 
gtk_image_set_from_pixbuf(GTK_IMAGE(image), gdk_pixbuf_loader_get_pixbuf(loader));

The application will compile and start correctly, but when accessing the method that contains this algorithm, I get the errors:

gdk_pixbuf_loader_write: assertion 'GDK_IS_PIXBUF_LOADER (loader)' failed
gdk_pixbuf_loader_get_pixbuf: assertion 'GDK_IS_PIXBUF_LOADER (loader)' failed

Anyone know where I am going wrong?

MamaShark
  • 19
  • 2

1 Answers1

0

The reason why it doesn't work, is because you haven't initialized your GdkPixbufLoader yet. In other words, you probably want to use something like gdk_pixbuf_loader_new() first. Note that you should also use g_object_unref() when you're done with it (to make sure its resources are deallocated).

To get more information about the GdkPixbufLoader class and how to use it, you might want to visit https://docs.gtk.org/gdk-pixbuf/class.PixbufLoader.html

nielsdg
  • 2,318
  • 1
  • 13
  • 22