WPF - 透明度 - 流式传输桌面内容

发布于 2024-10-06 07:20:33 字数 686 浏览 2 评论 0原文

您好,

我正在为游戏(星际争霸 II)制作记分板。此记分板是作为带有 C# 代码隐藏的 WPF 应用程序制作的。我已经有了一个在 WinForms 中可以运行 90% 的版本,但我缺乏 WPF 中提供的支持来轻松​​使其看起来更好。

该应用程序的目的是在正在运行的游戏之上形成一种覆盖层。该游戏处于全屏(窗口模式),因此在 WinForms 中我对它进行了编码,以便它始终位于顶部。它会这样做,这没问题。

由于 WPF 中应用程序的主要外观基于具有透明背景的图像,因此我已将大多数背景值设置为透明。但是,当我这样做时,整个应用程序不会被流软件注册。例如,它只显示我的桌面或我正在玩的游戏,但不显示我的应用程序,即使它在那里。我亲眼看到,但直播里的观众看不到。

有没有人对这件事有任何经验,因为它真的让我很头疼。如果它在流上不可见,我的整个应用程序将毫无用处。如果我必须将背景设置为颜色而不是透明,则用户界面在外观上也会被完全破坏。

我基本上是想用 C# 和 C# 制作游戏叠加层。 WPF。我读过您也可以通过不同的方式做到这一点,但我对 C++ 知之甚少,也不了解 DirectX,

感谢您花时间阅读并提供可能的见解。

编辑:最好的解决方案是类似于 Steam/Xfire/Dolby Axon 的覆盖层。

编辑2:我对所有建议都没有运气,所以我基本上将图像的透明位设为不透明,并让用户根据他们将使用的流媒体软件来决定使用哪一个。

Greetings

I'm in the process of making a Scoreboard for a game (Starcraft II). This scoreboard is being made as a WPF Application with a C# code-behind. I already have a version which works for 90% in WinForms but I lacked the support to easily make it look a lot nicer which are available in WPF.

The point of this application will be to form a kind of overlay on top of a running game. This game is in Fulscreen(Windowed Mode) so when in WinForms I coded it so that it should always be on top. It would do so and that was no problem.

Since the main look of the app in WPF is based on an image with a transparent background I have set most Background values to Transparent. However when I do this the entire application does not get registered by streaming software. For example it just shows my Desktop or the game I'm playing but not my application even though it IS there. I can see it with my own eyes but the audience on the stream cannot.

Does anyone have any experience with this matter because it's really doing my head in. My entire application will be useless if it is not visible on streams. If I have to put the background on a color rather than transparent the UI will be completely demolished as well in terms of looks.

I'm basically trying to make a game-overlay in C# & WPF. I have read you can do this on different ways as well but I have little to no knowledge of C++ nor do I know anything about DirectX

Thank you for your time reading and your possible insights.

Edit: The best solution would be an overlay similar to that one of Steam/Xfire/Dolby Axon.

Edit 2: I've had no luck with all the suggestions so I basically made the transparent bits of my image non transparent and let the user decide which one to use depending on what streaming software they would be using.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

停滞 2024-10-13 07:20:33

我在 WPF 中的透明度方面也遇到了同样的问题。当您将透明度设置为零时,它不会拾取任何内容。将其设置为最小值,然后流媒体软件将能够拾取它。

I had same issue with Transparency in WPF. When you set transparency to zero, it doesn't have anything to pick up. Set it to the minimum value, then streaming software will be able to pick it up.

困倦 2024-10-13 07:20:33

只是一个想法,但是如果你让它几乎透明(即 alpha = 0.01 左右)怎么办?然后它应该有足够的“物质”来被流媒体拾取,但仍然足够不可见,不会干扰视图。

Just an idea, but what if you make it only almost transparent (i.e. alpha = 0.01 or so)? Then it shoud have enough "substance" to be picked up by the streaming, but still be invisible enough to not disturb the view.

情绪操控生活 2024-10-13 07:20:33

一种可能性是 Alpha 混合完全在 GPU 上完成,从而阻止流媒体软件找到它。因此,您可以尝试在 WPF 应用程序中强制进行软件渲染。您可以通过设置:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly

One possibility is that the alpha-blending is being done totally on the GPU, preventing the streaming software from finding it. So you might try forcing software rendering in your WPF app. You can do that by setting:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly

挽心 2024-10-13 07:20:33

由于您还没有收到任何回复,我想我建议采取稍微不同的方法。

创建一个设置为 MDIParent 的 WinForm。然后,您发送一个 Win32API 命令,将游戏作为子窗口引入您的应用程序,删除边框,并将其最大化。

IntPtr Parent = hWnd of your main form.
IntPtr hWnd = Win32.User.FindWindow(null, "TheGame");
Win32.User.SetParent(hWnd, Parent);
// Get current window style of child form
int style = Win32.User.GetWindowLong(hWnd, Win32.User.GWL_STYLE);
// Take current window style and remove WS_CAPTION and WS_BORDER from it
Win32.User.SetWindowLong(hWnd, Win32.User.GWL_STYLE, (style & ~Win32.User.WS_CAPTION & ~Win32.User.WS_BORDER));
// Maximize within parent
Win32.User.ShowWindow(hWnd, Win32.User.SW_SHOWMAXIMIZED);

注意:Win32.User 类只是相应 Win32 互操作命令的普通包装器。

您现在应该能够通过直接 GDI+ 到 hWnd 或在其顶部放置一些东西来在此窗口顶部进行绘制。您遇到的透明度问题可能需要您进行一些手动复制,即在某处渲染界面,然后将其逐像素复制到目标窗口,跳过任何透明像素。

我希望这是有用的或者至少可以激发一些想法。

编辑:
您也可能会发现这个有趣:
http://blog.tedd.no/index.php/2010/08/16/c-image-analysis-auto-gaming-with-source/

示例应用程序允许您在显示图像之前对其进行修改。您只需向其中添加简单的模块即可获取输入并设置输出。但对于真正的游戏来说太慢了。 :)

编辑2:刚刚遇到设置LayeredWindowAttributes。不确定它是否有效,但您可以使用此调用(请参阅上面有关查找窗口的代码)来设置透明度颜色。

Since you haven't received any response yet I thought I'd suggest a slightly different approach.

Make a WinForm which you set to MDIParent. Then you send a Win32API-command to bring the game into your application as a child window, remove the borders, maximize it.

IntPtr Parent = hWnd of your main form.
IntPtr hWnd = Win32.User.FindWindow(null, "TheGame");
Win32.User.SetParent(hWnd, Parent);
// Get current window style of child form
int style = Win32.User.GetWindowLong(hWnd, Win32.User.GWL_STYLE);
// Take current window style and remove WS_CAPTION and WS_BORDER from it
Win32.User.SetWindowLong(hWnd, Win32.User.GWL_STYLE, (style & ~Win32.User.WS_CAPTION & ~Win32.User.WS_BORDER));
// Maximize within parent
Win32.User.ShowWindow(hWnd, Win32.User.SW_SHOWMAXIMIZED);

Note: The Win32.User class is just a vanilla wrapper for the corresponding Win32 interop commands.

You should now be able to draw on top of this Window either by GDI+'ing directly to the hWnd or putting something on top of it. The problem you are having with transparency may require you to do some manual copying, that is you render your interface somewhere, then copy it pixel by pixel to the destination window skipping any transparent pixels.

I hope this is useful or at least can spark some ideas.

EDIT:
Also you may find this interesting:
http://blog.tedd.no/index.php/2010/08/16/c-image-analysis-auto-gaming-with-source/

The sample app allows you to modify the image before it is displayed. You just add simple modules to it that gets input and sets output. Way too slow to use for real gaming though. :)

EDIT2: Just came across SetLayeredWindowAttributes. Not sure if it works, but you can use this call (see my code above on finding window) to set transparency color.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文