C# - 透明键不能正常工作

C# - 透明键不能正常工作

问题描述:

我目前将背景颜色设置为我的表单蓝色.我还将透明度键设置为等于表单的背景颜色.

I currently set the background color to my form blue. I also set the transparency key equal to the back color of the form.

如您所见,它正在做一些事情,但并没有消除所有的蓝色.我怎样才能解决这个问题,这样所有的蓝色都会消失?

As you can see, it is doing something, but it didn't get rid of all of the blue. How can I fix this problem so all the blue will go away?

您需要禁用抗锯齿并处理不稳定的闪屏,或者在 WPF 中创建闪屏.如果您的游戏是在 Winforms 中制作的,那么您仍然可以通过 WPF 应用程序启动它.

如果我是对的,这是使用 TransparencyKey 而不是 GDI+ 的固有问题.尝试使用 TransparencyKey 执行相同的过程,但使用 GDI+ 在表单的画布上绘图,而不是将图像放下.

You'll need to either disable anti-aliasing and deal with a choppy splash screen, or create the splash screen in WPF. If your game is made in Winforms then you can still start it up via a WPF application.

If I'm correct, this is the inherent problem with using TransparencyKey instead of GDI+. Try doing the same process with TransparencyKey, but draw on the form's canvas with GDI+ instead of plopping down an image.

您可以在表单的绘制事件中绘制图像.您可以通过调用 this.Invalidate();

You can draw the image in your form's paint event. You can call the paint event whenever you want by calling this.Invalidate();

作为一些指导,您的绘制事件需要使用 Graphics 类.您可以使用 Graphics g = this.CreateGraphics();

Just as a bit of guidance, your paint event will need to use the Graphics class. You can obtain the Graphics class of the form to paint with using Graphics g = this.CreateGraphics();

然后您可以执行诸如 g.Draw...(); 之类的操作.查看文档以获得更多帮助或对我的回答发表评论,我可以为您指明正确的方向.

You can then do stuff like g.Draw...();. Check documentation for more help or comment on my answer and I can point you in the right direction.