GTK设置背景图片,背景图片平铺显示

gtk set background image scale

#include 


int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *layout;
    GdkScreen *gdk_screen;
    GdkPixmap *background;

    gtk_init(&argc, &argv);

    gdk_screen = gdk_screen_get_default();
    gint screen_width = gdk_screen_get_width(gdk_screen);
    gint screen_height= gdk_screen_get_height(gdk_screen);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_fullscreen((GtkWindow*)window);

    GdkPixbuf *src_pixbuf = gdk_pixbuf_new_from_file("bk.jpg", NULL);
    GdkPixbuf *dst_pixbuf = gdk_pixbuf_scale_simple(src_pixbuf, screen_width, screen_height, GDK_INTERP_BILINEAR);

    gdk_pixbuf_render_pixmap_and_mask (dst_pixbuf, &background, NULL, 0); 
    GtkStyle *style = gtk_style_new (); 
    style->bg_pixmap[0] = background;
    gtk_widget_set_style (GTK_WIDGET(window), GTK_STYLE(style));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
~   

你可能感兴趣的:(Linux)