具有Alpha通道的C#半透明启动画面

时间:2018-08-18 12:55:18

标签: c# winforms gdi+ splash-screen

我试图在C#WinForms( WPF)中创建具有半透明图像(32位PNG)的启动屏幕。 但是,我无法使其正确显示。

这是我正在使用的图像(为清楚起见,透明性棋盘格):

enter image description here

我尝试过的解决方案:

1:使用TransparencyKey

由于图片还使用了部分透明区域,因此给出了不希望的结果。

enter image description here

2:覆盖OnPaintBackground

bool painted = false;

protected override void OnPaintBackground(PaintEventArgs e)
{
    if (painted) return;
    e.Graphics.DrawImage(BackgroundImage, new Point(0, 0));
    painted = true;
}

使用上面的代码(找到here)产生了另一个不希望的结果,因为背景只是黑色。

enter image description here

结论:

有什么方法可以在WinForms中创建这样的启动屏幕吗?

1 个答案:

答案 0 :(得分:1)

我现在通过使用this CodeProject article中有关Alpha Blended Forms的代码解决了该问题。 (感谢Hans Passant建议使用按像素的Alpha混合)