C#调节图片的透明度
原创
©著作权归作者所有:来自51CTO博客作者usdoc的原创作品,请联系作者获取转载授权,否则将追究法律责任
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();