Re: reading a png picture from memory
- From: Tristan Van Berkom <vantr touchtunes com>
- To: Stephane Pontier <stephane pontier free fr>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: reading a png picture from memory
- Date: Thu, 24 Oct 2002 10:44:46 -0400
this is the first few lines of gdk_pixbuf_new_from_file
in gdk-pixbuf-io.c.
as you can see... it reads 128 bytes from the beginning of
the file to read the header and choose a image loader
to do the rest.
you could easily change this function prototype
and first few lines to suit your needs.
happy hacking!
-Tristan.
===================================================
GdkPixbuf *
gdk_pixbuf_new_from_file (const char *filename,
GError **error)
{
GdkPixbuf *pixbuf;
int size;
FILE *f;
guchar buffer [128];
GdkPixbufModule *image_module;
g_return_val_if_fail (filename != NULL, NULL);
f = fopen (filename, "rb");
if (!f) {
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open file '%s': %s"),
filename, g_strerror (errno));
return NULL;
}
size = fread (&buffer, 1, sizeof (buffer), f);
if (size == 0) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image file '%s' contains no data"),
filename);
fclose (f);
return NULL;
}
image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
if (image_module == NULL) {
fclose (f);
return NULL;
}
================================================
Stephane Pontier wrote:
Hi everyone,
I'm trying to display a picture from a zipped file into a GTK+(1.2)
application.
I can already display this picture if it's stored on the hard drive (in
png format) using the gdk_pixbuf_new_from_file function, now I can read
a zip file containing png pictures, use zlib to inflate the picture file
in a buffer in memory but I don't know how to put it into a pixbuf.
Do I need to:
- save the buffer in a temporary file then load it with
gdk_pixbuf_new_from_file
- use another librairy to transform this png in memory into a
"8-bit/sample packed format" as specified in the
gdk_pixbuf_new_from_data function manual
or
- can I use something simpler ?
thank to reply to my email as I'm not subscribed to this list.
Stephane Pontier
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]