Live Chat Icon For mobile
Live Chat Icon

How to draw a faded image?

Platform: WinForms| Category: Bitmaps and Images

The trick is to use an alpha component while drawing the image.


// transparency should be in the range 0 to 1
protected void DrawScrollImage(Graphics g, Rectangle rect, Image image, float transparency)
{
	ImageAttributes ia = new ImageAttributes(); 
	ColorMatrix cm = new ColorMatrix(); 
	cm.Matrix00 = 1; 
	cm.Matrix11 = 1; 
	cm.Matrix22 = 1; 
	cm.Matrix33 = transparency; 
 
	ia.SetColorMatrix(cm); 

	g.DrawImage(image, rect, 0, 0, image.Width, image.Height, 
		GraphicsUnit.Pixel, ia); 
}

Share with

Related FAQs

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

Please submit your question and answer.