C#调节图片的透明度


C#调节图片的透明度


/// 
        /// 调节图片的透明度
        /// 
        /// 图像对象
        /// 调节度
        /// 调节后的图形对象
        public static Bitmap imgAlpha(Bitmap bitmapImg, int alpha)
        {
            Bitmap bitmap = new Bitmap(bitmapImg.Width, bitmapImg.Height, PixelFormat.Format32bppArgb);
            for (int h = 0; h < bitmapImg.Height; h++)
            {
                for (int w = 0; w < bitmapImg.Width; w++)
                {
                    Color color = bitmapImg.GetPixel(w, h);
                    bitmap.SetPixel(w, h, Color.FromArgb(alpha / 100, color.R, color.G, color.B));
                }
            }
            return bitmap;
        }
 //方法条调用
  Bitmap bitmap = imgAlpha(new Bitmap(@"F:\temp\image2.jpeg"), 12000);
            bitmap.Save(@"F:\temp\0001.png");
            bitmap.Dispose();

你可能感兴趣的:(图片透明度调节,C#调节图片透明度)