Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace ImageUtils
- {
- class ImageTransparency
- {
- public static Bitmap ChangeOpacity(Image img, float opacityvalue)
- {
- // Create a new bitmap with same dimensions as original
- Bitmap bmp = new Bitmap(img.Width,img.Height);
- ColorMatrix colormatrix = new ColorMatrix();
- colormatrix.Matrix33 = opacityvalue;
- ImageAttributes imgAttribute = new ImageAttributes();
- imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
- Rectangle srcRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
- using (Graphics graphics = Graphics.FromImage(bmp))
- {
- graphics.DrawImage(img, srcRect, 0, 0, img.Width, img.Height,
- GraphicsUnit.Pixel, imgAttribute);
- }
- return bmp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement