- 论坛徽章:
- 0
|
void
update_widget_bg(GtkWidget *widget, gchar *img_file)
{
GtkStyle *style;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
gint width, height;
pixbuf = gdk_pixbuf_new_from_file(img_file, NULL);
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
pixmap = gdk_pixmap_new(NULL, main_win.w, main_win.h, -1);
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0);
style = gtk_style_copy(GTK_WIDGET (widget)->style);
if (style->bg_pixmap[GTK_STATE_NORMAL])
g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]);
style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap);
#if 1
style->bg_pixmap[GTK_STATE_ACTIVE] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_PRELIGHT] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_SELECTED] = g_object_ref(pixmap);
style->bg_pixmap[GTK_STATE_INSENSITIVE] = g_object_ref(pixmap);
#endif
gtk_widget_set_style(GTK_WIDGET (widget), style);
g_object_unref(style);
}
我用这个设置一个窗口的背景(读取图片),如果图片的大小未1290*1080,
而我在一个800*480的屏上显示,图片的部分就显示不出来,我如何缩放图片使
图片完整的充满窗口。 |
|