c++ - Why is my cairo_surface_t drawing semi-transparent? -


i trying draw png image, contents of have in memory in argb32 format, using c++ cairo , gtk on ubuntu.

first, create gtkdrawingarea, on expose-event draw solid blue background red line top left bottom right, create surface , try draw onto drawing area. here's expose-event callback:

unsigned char *pcairobuf = ...  ....  gboolean ondrawingareaexposeevent(gtkwidget *pwidget, gdkeventexpose *pevent, gpointer data) {     cairo_t *cr = gdk_cairo_create(pwidget->window);      cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);     cairo_rectangle(cr, 0.0, 0.0, pevent->area.width, pevent->area.height);     cairo_fill(cr);      cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);     cairo_set_line_width(cr, 10.0);     cairo_move_to(cr, 0.0, 0.0);     cairo_line_to(cr, pevent->area.width, pevent->area.height);     cairo_stroke(cr);      // use existing buffer pcairobuf has (irenderwidth * irenderheight * 4) bytes, 4 bytes per pixel argb32 , 0 row padding        cairo_surface_t *psurface = cairo_image_surface_create_for_data(pcairobuf, cairo_format_argb32, irenderwidth, irenderheight, (irenderwidth * 4));      cairo_set_source_surface(cr, psurface, 0.0, 0.0);     cairo_paint(cr);      cairo_destroy(cr);      return true; } 

the drawing area , image both 244x278 pixels. image image of smokey bear's head , transparent around head:

enter image description here

and expect final result this:

enter image description here

but ends looking this:

enter image description here

i did not add code shows how got data buffer pcairobuf because figured cloud issue, perhaps i'm wrong? figured there's else i'm doing wrong having cairo surfaces, etc. explain difference between i'm expecting , i'm getting.

thanks in advance help!

as guess, not having used of libraries, i'd alpha channel's uniform across image , rendering's applying parts of image you'd non-transparent. try applying alpha channel pixels you'd transparent.


Comments