C#调节图片的透明度


C#调节图片的透明度


/// <summary>
        /// 调节图片的透明度
        /// </summary>
        /// <param name="bitmapImg">图像对象</param>
        /// <param name="alpha">调节度</param>
        /// <returns>调节后的图形对象</returns>
        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();
发布了27 篇原创文章 · 获赞 8 · 访问量 3515

猜你喜欢

转载自blog.csdn.net/Kiss_code/article/details/78384973
今日推荐