next up previous contents
Next: Border: example_colorborder.c Up: Image Processing using GTK. Previous: Image Inversion   Contents

Drawing Border

Draws a simple border of the given colour around the image. It destroys the pixels present there though!

Figure: Kathakali, With Border
Image kathakali_colorborder

void draw_normal_border(GdkPixbuf *pb,int red,int green,int blue)
{
  int ht,wt;
  int i=0,j=0;
  int flag=0;
  int border=10; //10 pixels wide border.
  int rowstride=0;
  gchar *pixel;

  ht=gdk_pixbuf_get_height(pb);
  wt=gdk_pixbuf_get_width(pb);
  pixel=gdk_pixbuf_get_pixels(pb);
  rowstride=gdk_pixbuf_get_rowstride(pb);


  for(i=0;i<ht;i++)
    for(j=0;j<rowstride;j+=3)
      {
	flag=0;//reset flag every time.

	if(i< (border))
	  flag=1;
	else if(i > (ht-border))
	  flag=1;
	else if(j < (border)*3)
	  flag=1;
	else if(j > (wt-border)*3)
	  flag=1;

	
	if(flag==1)
	  {
	    pixel[i*rowstride+j+0]=red;
	    pixel[i*rowstride+j+1]=green;
	    pixel[i*rowstride+j+2]=blue;
	  }
      }
  return;
}

See you soon!
Cheers
Muthu
The intricacies of GTK are too good!

Appendix


Muthiah 2004-06-04