本文介绍了半透明PNG作为开机画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个闪屏4的Windows应用程序。

I'm trying to make a Splash Screen 4 an Win application.

我的设置:

表格边框样式设置为无。起始位置是屏幕中央。
形式的背景图像设定为一个PNG文件,圆边和一个建立阴影

form border style is set to none. start position is screen center.background image of the form is set to a PNG file, with rounded edges and a "build in" drop shadow.

在code我设置:

this.SetStyle( ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle( ControlStyles.UserPaint, true);
this.SetStyle( ControlStyles.DoubleBuffer, true);
this.SetStyle( ControlStyles.SupportsTransparentBackColor, true);

this.AllowTransparency = true;
this.BackColor = Color.Transparent;

但是当我测试,它说,该形式不能有一个透明的背景颜色。

but when i test, it says that the form can't have a transparent background color.

我不希望设置一个透明键辩论,因为这会造成麻烦与dropschadow(巴新的半透明部分)

i DO NOT want to set a transparency key, cuz it causes trouble with the dropschadow ( semi transparent part of the png )

我也不想不透明度设置为0%,cuz它也影响我的PNG。

also i dont want to set opacity to 0%, cuz it also effects my PNG.

其实我只是想显示为窗口只有我PNG。 additionaly会出现在它上面的一些动态文本,并在未来的过程吧......

in fact i just want ONLY my png shown as the window. additionaly there will be some dynamic text on top of it and a process bar in the future...

任何想法?如何分辨是可以有透明的背景形式的 Adob​​e Photoshop等CS5的启动画面

Any ideas? how to tell the form that is CAN have transparent background like the splash screen of ADOBE PHOTOSHOP CS5

推荐答案

我花了寻找一种方式,在Win形式做这几个小时也所以我想我会分享我的解决方案。

I spent a few hours looking for a way to do this in Win Forms as well so I thought I would share my solution.

我的闪屏图像具有透明背景,并且延伸到透明背景的各种阴影的.png。使用罕见的颜色为具有透明度键沿控制的背景留下难看的补丁半透明的阴影下。

My splash screen image is a .png with a transparent background and various shadows that extend over the transparent background. Using uncommon colors as the background of the control along with a transparency key left ugly patches underneath the semi-transparent shadows.

我能够通过设置形式,我想显示图像的背景图像和覆盖OnPaintBackground功能,像这样来获得期望的结果:

I was able to get the desired result by setting the background image of the form to the image I wanted to display and overriding the OnPaintBackground function like so:

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

我只撞这个古老的线程,因为它是谷歌顶级的结果,我尝试了一些不同的关键字组合。

I'm only bumping this old thread because it's the top Google result for a few different keyword combos that I tried.

另请参阅这是我发现从另一个SO后此解决方案。

See also Transparent Splash Screen which is where I found this solution from another SO post.

这篇关于半透明PNG作为开机画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:17