开发者

WPF - Transparency - Stream Desktop Content

开发者 https://www.devze.com 2023-01-29 01:48 出处:网络
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%

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 loo开发者_高级运维k 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.


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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消