Load data to GdkPixbufLoader from g_input_stream_read
I load some data from file:
GInputStream* input_stream;
GFile *file = g_file_new_for_path(file_path);
input_stream = g_file_read(开发者_StackOverflow中文版file,generator_cancellable ,NULL);
g_input_stream_read(input_stream, buffer, sizeof (buffer),generator_cancellable,error);
How can i load g_input_stream_read
function result to the GdkPixbufLoader object?
Thank you.
You need to create a new GdkPixbufLoader
and pass the data you read from GInputStream
to it:
GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
gint num_bytes = g_input_stream_read (input_stream, buffer, ...);
gdk_pixbuf_loader_write (loader, buffer, num_bytes, error);
However, this makes sense if you perform reading asynchronously or in chunks (to e.g. show a progressively loaded JPEG or PNG). If you just read all the data at once in a blocking manner, use simpler gdk_pixbuf_new_from_stream()
.
精彩评论