设置图片透明度的四种方法
方法一:像素法
即循环扫描整张图片,设置每一个像素的Alpha通道的值。 由于是一个个像素的处理,所以这种方法效率很低。
///
/// 设置图片的透明度
///
/// 原图
/// 透明度(0-255之间)
///
public static Bitmap SetBitmapAlpha(Bitmap bitmap, int alpha)
{
Bitmap bmp = (Bitmap)bitmap.Clone();
Color color;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
color = bmp.GetPixel(x, y);
bmp.SetPixel(x, y, Color.FromArgb(alpha, color));
}
}
bitmap.Dispose();