How to draw a shadow for a given transparent image?

Platform: WinForms| Category: Bitmaps and Images

The following method will draw a shadow of the supplied image at the specified
location.

The general usage pattern is to call this method first to draw a shadow at a

(2,2) offset from where the original image will be drawn and then draw the

original image itself.


public static void DrawShadow(Graphics g, Image iconImage, int left, int top)
{
	ImageAttributes ia = new ImageAttributes();
	ColorMatrix cm = new ColorMatrix();
			
	cm.Matrix00 = 0;
	cm.Matrix11 = 0;
	cm.Matrix22 = 0;
	cm.Matrix33 = 0.25f;
			
	ia.SetColorMatrix(cm);
	
	g.DrawImage(iconImage, new Rectangle(left, top, iconImage.Width, 

iconImage.Height), 0, 0, iconImage.Width, iconImage.Height,
		GraphicsUnit.Pixel, ia);
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.