Skip to content

Instantly share code, notes, and snippets.

@abe238
Created June 29, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abe238/b662c5267fc4bf539396 to your computer and use it in GitHub Desktop.
Save abe238/b662c5267fc4bf539396 to your computer and use it in GitHub Desktop.
Change Image Opacity
public static Bitmap ChangeOpacity(Image img, float opacityvalue)
{
Bitmap bmp = new Bitmap(img.Width, img.Height);
Graphics graphics = Graphics.FromImage(bmp);
ColorMatrix colormatrix = new ColorMatrix();
colormatrix.Matrix33 = opacityvalue;
ImageAttributes imgAttribute = new ImageAttributes();
imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute);
graphics.Dispose();
return bmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment