Victor Image Processing Library How-to Tips

Drop Shadow

The drop shadow is a silhouette that is lightened and blurred and appears behind the source object. It gives the illusion of depth to an image.

Drop Shadow
Text with drop shadow
Sasafras Leaves
Sasafras Leaves
Leaves with Drop Shadow
Leaves with drop shadow

Two techniques are illustrated here --

In both techniques the shadow is constructed by creating a black and white image, brightening it to a medium gray, then blurring (severely). The text or object is then placed on top of the shadow.

Text with Drop Shadow - the Source Code

This function creates some text and a drop shadow. Requires Victor Image Processing Library for 32-bit Windows v 6.0 or higher.
int text_with_shadow(imgdes *resimg)
{
	imgdes tmptext;
	int rcode = NO_ERROR;
	char *caption="Drop Shadow";
	int textheight;
	rcode = allocimage(&tmptext, 430, 86, 8);
	if(rcode == NO_ERROR) {
		zeroimage(255, &tmptext);
		color = 0x808080;   // Gray
		textheight = 48;	   // 48 pt
		tmptext.stx += 6;    // Offset the shadow by (6,6)
		tmptext.sty += 6;
		addtext(color, textheight, "ARIAL BOLD", caption, &tmptext);
		for(j=0; j<25; j++)
                     blur(&tmptext, &tmptext);
                     color=0;   // Black
		tmptext.stx -= 6;    // Restore starting position
		tmptext.sty -= 6;;
		freeimage(resimg);	// Replace original image with this image
		copyimgdes(&tmptext, resimg);
	}
	return(rcode);
}


Drop Shadow of an Object - the Source Code

This function creates a drop shadow for all portions of the image that are not white. Works best for 8-bit grayscale and 24-bit color images. Requires Victor Image Processing Library v 6.0 or higher.
// Creates a shadow of non-white portions of source image
int object_shadow(imgdes *srcimg, imgdes *desimg)
{
   imgdes tmpsrc;
   int rcode = NO_ERROR, j, shadow_width=20, shadow_height=20, cols, rows;
   cols = CALC_WIDTH(srcimg);
   rows = CALC_HEIGHT(srcimg);
   allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount);
   zeroimage(255, &tmpsrc);
   tmpsrc.stx=shadow_width;
   tmpsrc.sty=shadow_height;
   copyimage(srcimg, &tmpsrc);
   tmpsrc.stx = 0;
   tmpsrc.sty = 0;
   kodalith(254, &tmpsrc, &tmpsrc);
   changebright(128, &tmpsrc, &tmpsrc);
   for(j=0; j<25; j++)
                  blur(&tmpsrc, &tmpsrc);
                  multiplyimage(srcimg, &tmpsrc, desimg);
                  freeimage(&tmpsrc);
                  return(rcode);
                  }

Copyright © 1997 - 2006 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.


Victor Image Processing Library homepage | Victor Sample Code