Transparent Pixbufs



Hi,
   I'm trying to load a partly transparent image into a pixbuf.
Basically, to keep it short, the opaque parts of the image show up with
diagonal lines and, I think, black and white. It only happens on an
image with transparency with no code changes. I'm guessing this is
indicative of something obviously wrong that I've done but I'm not sure
what, hope you can help. I've attached a cut-down code sample to show
what I'm doing.
Thanks,
John
#include<gtk/gtk.h>

GdkPixbuf *pixbuf;
GtkWidget *window;

static gint
expose_da( GtkWidget *widget, GdkEventExpose *event, gpointer data )
{
	guchar *pixels;
	int rowstride;

	rowstride = gdk_pixbuf_get_rowstride( pixbuf );

	pixels = gdk_pixbuf_get_pixels( pixbuf ) + rowstride * event->area.y + event->area.x * 3;

	gdk_draw_rgb_image_dithalign (widget->window,
		widget->style->black_gc,
		event->area.x, event->area.y,
		event->area.width, event->area.height,
		GDK_RGB_DITHER_NORMAL,
		pixels, rowstride,
		event->area.x, event->area.y );


	return TRUE;
}

int
main( int argc, char *argv[] )
{
	//GtkWidget *da;
	gint width, height;
	GdkPixbuf *image;
	GError **error = NULL;
	gtk_init( &argc, &argv );

	window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
	//da = gtk_drawing_area_new();
	g_signal_connect( window, "expose_event",
		G_CALLBACK( expose_da ), NULL );

	image = gdk_pixbuf_new_from_file( argv[1], error );

	//gtk_container_add( GTK_CONTAINER( window ), da );
	width = gdk_pixbuf_get_width( image );
	height = gdk_pixbuf_get_height( image );
	//pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, width, height );
	//gdk_pixbuf_copy_area( image, 0, 0, width, height, pixbuf, 0, 0 );
	pixbuf = image;
	gtk_widget_set_size_request( window, width, height );
	gtk_widget_queue_draw( window );
	gtk_widget_show_all( window );
	gtk_main();
	return 0;
}


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