C# Winform设置图片透明度。
ImagenewImage=Image.FromFile("图片1.jpg");Graphicsg=this.CreateGraphics();g.DrawImage(n...
Image newImage = Image.FromFile("图片1.jpg");
Graphics g = this.CreateGraphics();
g.DrawImage(newImage, 0, 0);
想设置图片透明度,如何写? 展开
Graphics g = this.CreateGraphics();
g.DrawImage(newImage, 0, 0);
想设置图片透明度,如何写? 展开
2个回答
展开全部
//改变图片的透明度
private Image ChangeAlpha(Image image)
{
Bitmap img = new Bitmap(image);
using (Bitmap bmp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(img, 0, 0);
for (int h = 0; h <= img.Height - 1; h++)
{
for (int w = 0; w <= img.Width - 1; w++)
{
Color c = img.GetPixel(w, h);
bmp.SetPixel(w, h, Color.FromArgb(200, c.R, c.G, c.B));
}
}
return (Image)bmp.Clone();
}
}
}
调用:
Image image1 = Image.FromFile(Application.StartupPath + @"图片路径");
this.panel1.BackgroundImage = ChangeAlpha(image1);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询