Re: Some questions I\
- From: Olexiy Avramchenko <olexiy irtech cn ua>
- To: fredderic excite com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Some questions I\
- Date: Mon, 24 May 2004 17:18:59 +0300
Freddie Unpenstein wrote:
There's a few things that've been bugging me of late, and I was just wondering if anyone here could shed any
light on any of these points:
1) An easy way to determine what image format a file is encoded in, if in fact it is an image at all. (And
possibly obtain some basic image stats) At present I'm loading the entire image, just to see if it is an
image, and throw it away again. There are other ways, but although slow, this is the easiest. The closest I
can think of without resorting to running external programs, or fiddling around with image libraries, is to
use the progressive Image Loader. As I understand it, it will emit a signal as soon as it has basic image
configuration information. I don't recall from the documentation, however, how to determine the format of
the image being loaded?
I've attached small sample that shows how to do this with
GdkPixbufLoader. You can learn more at:
http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/GdkPixbufLoader.html
http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/gdk-pixbuf-Module-Interface.html#GdkPixbufFormat
PS: As for question 4) - when you get "size-prepared" signal, the image
dimensions are known, so you can use gtk_widget_size_request to resize
your widgets.
Olexiy
#include <stdio.h>
#include <stdlib.h>
#include <gdk/gdk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
static void get_format(GdkPixbufLoader *loader)
{
gchar **ss;
GdkPixbufFormat *format;
format = gdk_pixbuf_loader_get_format(loader);
g_return_if_fail(format!=NULL);
printf("%s\n", gdk_pixbuf_format_get_name(format));
ss = gdk_pixbuf_format_get_mime_types(format);
for (; *ss; ss++)
printf("\tMIME type: '%s'\n", *ss);
exit(0);
}
int main(int argc, char **argv)
{
char buffer[1024];
size_t size;
FILE *f;
GdkPixbufLoader *loader;
if (argc < 2) {
fprintf(stderr, "Usage: ff <filename>\n");
return -1;
}
gdk_init(&argc, &argv);
loader = gdk_pixbuf_loader_new();
g_signal_connect(loader, "size-prepared", G_CALLBACK(get_format), 0);
f = fopen(argv[1], "r");
if ( !f ) {
fprintf(stderr, "Can't open \"%s\"\n", argv[1]);
return -1;
}
while ( (size=fread(buffer, 1, sizeof(buffer), f)) > 0 )
gdk_pixbuf_loader_write(loader, buffer, size, NULL);
fclose(f);
return -1;
}
ff: ff.c
gcc -Wall `pkg-config --cflags --libs gdk-pixbuf-2.0 gdk-2.0` $< -o $@
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]