Pixbuf / Pixmap



Hi:


I've written this little example to show my problem. Sometimes I need to
load PNG's and other files from a pixbuf, then store it in a pixmap, and
then put it again in a pixbuf, as some functions as gtk_window_set_icon
just accepts a pixbuf as parameter. The problem is that the new icon has
not transparent background. I suppose I have to perform any combination
between the pixmap and the mask, or maybe change the graphics context of
the pixmap, but after ten hours I can't obtain anything. I've tried all
I could imagine reading Gdk and GdkPixbuf api docs, but nothing...

Could anyone help me, please?


#include <gtk/gtk.h>
#include <stdio.h>

int main (int argc,char *argv[])
{
        GtkWidget *window;
        GtkHBox *box;
        GtkImage *image1,*image2,*image3;
        GdkPixbuf *pixbuf,*pixbuf2;
        GdkPixmap *pixmap;
        GdkBitmap *bitmap;
        GdkScreen*  scr;
        gint depth;
        gint myw,myh;
                
        gtk_init (&argc, &argv);
        
        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
        box=gtk_hbox_new(TRUE,1);
        
        /* I read a PNG icon from a file */
        pixbuf=gdk_pixbuf_new_from_file("execution.png",NULL);
        
        /* Values to create a pixmap and a bitmap */
        myw=gdk_pixbuf_get_width(pixbuf);
        myh=gdk_pixbuf_get_height(pixbuf);
        scr=gdk_screen_get_default();
        depth=(gdk_screen_get_system_visual(scr))->depth;
        
        /* I create the pixmap to receive the image and the bitmap to */
        /* receive the mask */
        pixmap=gdk_pixmap_new(NULL,myw,myh,depth);
        bitmap=gdk_pixmap_new(NULL,myw,myh,1);
        gdk_drawable_set_colormap (pixmap,gdk_colormap_get_system ());
        gdk_pixbuf_render_pixmap_and_mask(pixbuf,&pixmap,&bitmap,0);
                                      
        pixbuf2=gdk_pixbuf_get_from_drawable(NULL,pixmap,NULL,0,0,0,0,myw,myh);
        
        image1=gtk_image_new_from_pixmap(pixmap,NULL);
        image2=gtk_image_new_from_pixbuf(pixbuf2);
        image3=gtk_image_new_from_pixbuf(pixbuf);
        
        gtk_box_pack_start(box,image1,FALSE,FALSE,0);
        gtk_box_pack_start(box,image2,FALSE,FALSE,0);
        gtk_box_pack_start(box,image3,FALSE,FALSE,0);
        
        gtk_container_add(GTK_CONTAINER(window),GTK_WIDGET(box));
        gtk_window_set_icon(window,pixbuf2);
        gtk_widget_show_all(GTK_WIDGET(window));
        gtk_main();
        return 0;
}



-- 
Daniel Campos <danielcampos netcourrier com>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]