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();