03/01/2012 UPDATE:
Here's a simple working app that loads a "test.jpg" file near it (file size must be < 100000 bytes).
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
void on_destroy (GtkWidget *widget G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)
{
gtk_main_quit ();
}
int main (int argc, char *argv[])
{
FILE *f;
guint8 buffer[100000];
gsize length;
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf;
GtkWidget *window;
GtkWidget *image;
gtk_init (&argc, &argv);
f = fopen ("test.jpg", "r");
length = fread (buffer, 1, sizeof(buffer), f);
fclose (f);
loader = gdk_pixbuf_loader_new ();
gdk_pixbuf_loader_write (loader, buffer, length, NULL);
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
image = gtk_image_new_from_pixbuf (pixbuf);
gtk_container_add (GTK_CONTAINER (window), image);
gtk_widget_show_all (GTK_WIDGET (window));
g_signal_connect (window, "destroy", G_CALLBACK(on_destroy), NULL);
gtk_main ();
return 0;
}
Original Answer:
The char *
or unsigned char *
here has little importance.
gdk_pixbuf_new_from_data
will only read uncompressed RGB data (the only colorspace supported is GDK_COLORSPACE_RGB) with an alpha channel (RGBA) or without it (RGB). No wonder passing it JPEG fails.
Calling gdk_pixbuf_loader_write
looks like a better option, but we'd need some code to see what you may doing wrong. Check however that you have the pixbuf loader for jpg installed by running in a shell the gdk-pixbuf-query-loaders
command, and verifying that JPEG is there.