#include
#include
#include
#define BUF_SIZE 8192
GtkWidget *
load_image (const gchar *uri)
{
GnomeVFSHandle *handle;
GnomeVFSResult result;
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf;
gchar buffer[BUF_SIZE];
GnomeVFSFileSize bytes_read;
result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
loader = gdk_pixbuf_loader_new ();
while (result == GNOME_VFS_OK) {
result = gnome_vfs_read (handle, buffer,
BUF_SIZE, &bytes_read);
gdk_pixbuf_loader_write (loader, buffer, bytes_read, NULL);
}
gdk_pixbuf_loader_close (loader, NULL);
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (!pixbuf) {
return NULL;
}
return gtk_image_new_from_pixbuf (pixbuf);
}
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *image;
if (argc < 2) {
g_print ("Run with %s ,<2\n", argv[0]);
exit (1);
}
gtk_init (&argc, &argv);
gnome_vfs_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy",
gtk_main_quit, NULL);
image = load_image (argv[1]);
if (!image) {
g_print ("Not a valid uri: %s\n", argv[1]);
return (1);
}
gtk_container_add (GTK_CONTAINER (window), image);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
make.sh如下:
#!/bin/bash
gcc `pkg-config --libs --cflags gtk+-2.0 gnome-vfs-2.0` \
vfs-example.c -o vfs-example
阅读(1929) | 评论(0) | 转发(0) |