[cairo] how to use alpha blending by cairo?
lao wb
laowenbo at gmail.com
Tue Jun 27 20:45:26 PDT 2006
Hi
I am using GTK+ to do with my application. I have a bitmap without alpha
channel as my background, another bitmap with alpha channel to show above
through to see the background. At first, I tried to use gdk to do this,
still not succeed yet, always show only the last one gdk_draw_pixbuf
invokes in the expose handler.
here is my gdk sample code:
#include <gtk/gtk.h>
#define STD_WIDTH 680
#define STD_HEIGHT 480
static GdkPixbuf * s_basePix;
static GdkPixbuf * s_homeMenuPix;
gboolean on_expose(GtkWidget * widget,
GdkEventExpose * ps,
gpointer data)
{
GdkPixbuf * basePix;
GdkPixbuf * homeMenuPix;
homeMenuPix = s_homeMenuPix;
basePix = s_basePix;
gdk_draw_pixbuf(widget->window, widget->style->bg_gc[GTK_STATE_NORMAL],
s_basePix, 0, 0, 0, 0,
STD_WIDTH,
STD_HEIGHT,
GDK_RGB_DITHER_NONE,
0, 0);
gdk_draw_pixbuf(widget->window, widget->style->bg_gc[GTK_STATE_NORMAL],
s_homeMenuPix, 0, 0, 0, 0,
STD_WIDTH,
STD_HEIGHT,
GDK_RGB_DITHER_NONE,
0, 0);
return FALSE;
}
int main(int argc, char * argv[])
{
GtkWidget * mainWnd = NULL;
GdkDrawable * pixMap = NULL;
GtkWidget * img = NULL;
GtkWidget * box = NULL;
GtkWidget * button = NULL;
GdkBitmap * msk = NULL;
GdkBitmap * homeMenu = NULL;
GdkColormap * colorMap = NULL;
GdkScreen * screen = NULL;
gtk_init(&argc, &argv);
mainWnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(mainWnd), "test draw...\n");
gtk_signal_connect(GTK_OBJECT(mainWnd), "destroy", gtk_main_quit, NULL);
img = gtk_image_new();
gtk_container_add(GTK_CONTAINER(mainWnd), img);
gtk_signal_connect(GTK_OBJECT(img),
"expose-event",
GTK_SIGNAL_FUNC(on_expose),
NULL);
gtk_container_set_border_width(GTK_CONTAINER(mainWnd), 5);
gtk_widget_show_all(mainWnd);
screen = gdk_screen_get_default();
colorMap = gdk_screen_get_rgba_colormap(screen);
if(!colorMap)
colorMap = gdk_screen_get_rgb_colormap(screen);
homeMenu = gdk_pixmap_create_from_xpm(mainWnd->window,
&msk,
&mainWnd->style->bg[GTK_STATE_NORMAL],
"f:/homemenu.bmp");
s_homeMenuPix =
gdk_pixbuf_get_from_drawable(s_homeMenuPix,
homeMenu,
colorMap,
0, 0, 0, 0,
STD_WIDTH,
STD_HEIGHT);
pixMap = gdk_pixmap_create_from_xpm(mainWnd->window,
&msk,
&mainWnd->style->bg[GTK_STATE_NORMAL],
"f:/Sunset.bmp");
s_basePix =
gdk_pixbuf_get_from_drawable(s_basePix,
pixMap,
colorMap,
0, 0, 0, 0,
STD_WIDTH,
STD_HEIGHT);
gtk_main();
return 0;
}
I have posted this to gtk maillist, but noone reply.
Is there any cairo api can help me to composite pixbuf as my expect.
Any advice would be appreciated!
Laowb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20060628/7a941702/attachment.html
More information about the cairo
mailing list