Chinaunix首页 | 论坛 | 博客
  • 博客访问: 350742
  • 博文数量: 112
  • 博客积分: 5245
  • 博客等级: 大校
  • 技术积分: 1120
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-07 09:20
个人简介

静下来,定好方向,好好干。

文章分类
文章存档

2017年(1)

2012年(1)

2011年(5)

2010年(6)

2009年(16)

2008年(59)

2007年(24)

我的朋友

分类: LINUX

2008-07-23 22:03:33

#include
#include

gboolean resize_image(GtkWidget *widget, GdkEvent *event, GtkWidget *window)
{
    GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(widget));
    if (pixbuf == NULL)
    {
        g_printerr("Failed to resize image\n");
        return 1;
    }

    printf("Width: %i\nHeight%i\n", widget->allocation.width, widget->allocation.height);

    pixbuf = gdk_pixbuf_scale_simple(pixbuf, widget->allocation.width, widget->allocation.height, GDK_INTERP_BILINEAR);

    gtk_image_set_from_pixbuf(GTK_IMAGE(widget), pixbuf);

    return FALSE;
}

int main(int argc, char **argv)
{
    GtkWidget *window = NULL;
    GtkWidget *image = NULL;

    if (argc < 2 || argc > 3)
    {
        g_printerr("Usage: %s \n", argv[0]);
        return 1;
    }

    /* Initialize */
    gtk_init(&argc, &argv);

    /* Creat Widgets */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    image = gtk_image_new_from_file(argv[1]);
    if (image == NULL)
    {
        g_printerr("Could not open \"%s\"\n", argv[1]);
        return 1;
    }


/**/
    GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
    if (pixbuf == NULL)
    {
        g_printerr("Failed to resize image\n");
        return 1;
    }

    printf("Width: %i\nHeight%i\n", image->allocation.width, image->allocation.height);

    pixbuf = gdk_pixbuf_scale_simple(pixbuf, 600, 400, GDK_INTERP_BILINEAR);

    gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
/**/


    /* attach standard event handlers */
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    //g_signal_connect(image, "expose-event", G_CALLBACK(resize_image), (gpointer)window);

    gtk_container_add(GTK_CONTAINER(window), image);
    gtk_widget_show_all(GTK_WIDGET(window));

    gtk_main();

    return 0;
}
阅读(1063) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~