GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 5:57 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Probelm in setting clip mask on Pixmap (image background)
PostPosted: Thu Feb 14, 2008 1:59 pm 
Offline

Joined: Tue Feb 05, 2008 1:51 pm
Posts: 3
Hi,
I am facing problem in setting mask on pixamp using Gtk+ over DirectFB backend
.
The code i am using, is given below.

/*------------------------------------------------------------------*/
void SetPixels_And_DrawImage(int x,int y, int w, int h,int[] pixelArray,jint
offset,jint scansize)
{
guchar *rgbBuffer = NULL;
int height_index = 0;

GdkBitmap *mask = (GdkBitmap *) gdk_pixmap_new (NULL, w, h, 1);
GdkGC *maskGC = gdk_gc_new (mask);

GdkPixbuf *pPixbuf = NULL;
GdkPixmap *pixmap = (GdkPixmap *) gdk_pixmap_new (NULL, w, h,
gdk_visual_get_system ()->depth);
GdkGC *gc = gdk_gc_new (pixmap );

GdkColor opaque, transparent;

opaque.pixel = 1;
transparent.pixel = 0;

/* Fill mask with 1s */
gdk_gc_set_foreground (maskGC, &opaque);
gdk_draw_rectangle (mask, maskGC, TRUE, 0, 0, w, h);

for (n = 0; n < h; n++)
{

for (m = 0; m < w; m++)
{
/* Get the pixel at m, n. */
pixel = (unsigned long) pixelArray[n * scansize + m + offset];

/* Get and store red, green, blue values. */
rgbBuffer[height_index++] = (guchar) ((pixel & 0xff0000) >> 16);

rgbBuffer[height_index++] = (guchar) ((pixel & 0xff00) >> 8);

rgbBuffer[height_index++] = (guchar) (pixel & 0xff);

/* Check if pixel should be transparent. */
if((pixel & 0xff000000) == 0)
{
gdk_gc_set_foreground (maskGC,&transparent);
gdk_draw_point (mask, maskGC, x+m, y+n);
}
else
{
gdk_gc_set_foreground (maskGC, &opaque);
gdk_draw_point (mask, maskGC, x+m, y+n);
}
}
}

pPixbuf = gdk_pixbuf_new_from_data(rgbBuffer,GDK_COLORSPACE_RGB,FALSE,8,w,h,w
*3,NULL,NULL);

gdk_gc_set_clip_origin (gc, x, y);
gdk_gc_set_clip_mask (gc, mask);

gdk_draw_pixbuf (pixmap, gc, pPixbuf,0, 0, 0, 0,
gdk_pixbuf_get_width (pPixbuf), gdk_pixbuf_get_height
(pPixbuf),GDK_RGB_DITHER_NORMAL,0, 0);
}




/*------------------------------------------------------------------*/
In the above code, we are setting clip on mask using api "
gdk_gc_set_clip_mask " but in the case of icon image, the background should
be transparent.
But background of image is black.

Please help me to solve this problem.
Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group