当前位置: 技术问答>linux和unix
gtk 背景图片的问题
来源: 互联网 发布时间:2016-09-28
本文导语: GdkPixbuf *pixbuf = NULL; GdkPixmap *pixmap = NULL; GtkWidget *image = NULL; GdkPixbuf* scaled = NULL; gtk_widget_set_app_paintable(window,TRUE); gtk_widget_realize (window); /* load background */ ...
GdkPixbuf *pixbuf = NULL;
GdkPixmap *pixmap = NULL;
GtkWidget *image = NULL;
GdkPixbuf* scaled = NULL;
gtk_widget_set_app_paintable(window,TRUE);
gtk_widget_realize (window);
/* load background */
pixbuf = gdk_pixbuf_new_from_file (background,NULL);
image = gtk_image_new_from_pixbuf (pixbuf);
int src_w = gdk_pixbuf_get_width(pixbuf);
int src_h = gdk_pixbuf_get_height(pixbuf);
int dest_w = gdk_screen_get_width(gtk_widget_get_screen(window));
int dest_h = gdk_screen_get_height(gtk_widget_get_screen(window));
if( src_w != dest_w || src_h != dest_h )
{
scaled = gdk_pixbuf_scale_simple( pixbuf, dest_w, dest_h, GDK_INTERP_BILINEAR );
g_object_unref( pixbuf );
pixbuf = scaled;
}
pixmap = gdk_pixmap_new (window->window, dest_w, dest_h, -1);
gdk_pixbuf_render_to_drawable(pixbuf, pixmap,
(window)->style->fg_gc[GTK_STATE_NORMAL],
0,0,0,0,
dest_w,
dest_h,
GDK_RGB_DITHER_NORMAL,0,0);
g_object_unref(pixbuf);
gdk_window_set_back_pixmap ( (GtkWidget*)window->window, pixmap, FALSE);
gdk_window_clear( window->window );
gtk_widget_queue_draw(window);
用这种方法给window背景绘图,程序运行正常,可是当改变linux主题的时候或出现背景图变成白色的情况,为什么会这样?怎么解决,谢谢
|
是因为你的Linux系统没有安装gd库 如果是CentOS使用 yum install gd gd-devel
然后编译PHP时加上--with-gd 就可以了
然后编译PHP时加上--with-gd 就可以了