moel@345: using System; moel@345: using System.Collections.Generic; moel@345: using System.Text; moel@345: using System.Drawing; moel@345: using System.Runtime.InteropServices; moel@345: using System.Drawing.Imaging; moel@345: moel@345: namespace Aga.Controls moel@345: { moel@345: public static class BitmapHelper moel@345: { moel@345: [StructLayout(LayoutKind.Sequential)] moel@345: private struct PixelData moel@345: { moel@345: public byte B; moel@345: public byte G; moel@345: public byte R; moel@345: public byte A; moel@345: } moel@345: moel@345: public static void SetAlphaChanelValue(Bitmap image, byte value) moel@345: { moel@345: if (image == null) moel@345: throw new ArgumentNullException("image"); moel@345: if (image.PixelFormat != PixelFormat.Format32bppArgb) moel@345: throw new ArgumentException("Wrong PixelFormat"); moel@345: moel@345: BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), moel@345: ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); moel@345: unsafe moel@345: { moel@345: PixelData* pPixel = (PixelData*)bitmapData.Scan0; moel@345: for (int i = 0; i < bitmapData.Height; i++) moel@345: { moel@345: for (int j = 0; j < bitmapData.Width; j++) moel@345: { moel@345: pPixel->A = value; moel@345: pPixel++; moel@345: } moel@345: pPixel += bitmapData.Stride - (bitmapData.Width * 4); moel@345: } moel@345: } moel@345: image.UnlockBits(bitmapData); moel@345: } moel@345: } moel@345: }