Windows XP上的Wpf模糊窗口 [英] Wpf blur window on windows xp

查看:146
本文介绍了Windows XP上的Wpf模糊窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何模糊窗口背后的所有内容,例如网格背后?目的不是模糊窗口的一部分,而是窗口xp及更高窗口后面的所有内容。我听说过 dwmapi ,但这不适用于windows xp。我怎么能这样做?

解决方案

这并不容易。您将修改窗口的外观,而不是整个桌面,其中包含与您的应用程序无关的应用程序窗口,因此与WPF无关。



尽管如此,还是有一个解决方法。您必须复制整个桌面图像,然后创建自己的WPF窗口,该窗口覆盖所有背景并模仿它。此背景窗口应该是一个单独的顶级窗口,其属性 WindowStyle 设置为 System.Windows.WindowStyle.None

http ://msdn.microsoft.com/en-us/library/system.windows.window.windowstyle%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com /en-us/library/system.windows.windowstyle%28v=vs.110%29.aspx [ ^ ]。



It将允许您创建一个没有任何非客户区的窗口,以覆盖所有当前桌面以模仿桌面ppearance。在这个窗口中,您需要绘制从真实桌面复制的图形,模糊或您想要的方式。



有很多方法可以捕获屏幕。您可以在Web上搜索解决方案。

您还可以查看此开源项目的源代码: http://sourceforge.net/projects/screencapturewp [ ^ ]。



创建一些模糊效果(有很多不同类型的模糊,包括非常逼真但很难计算 boke ) ,你可以使用卷积矩阵

http:// en.wikipedia.org/wiki/Kernel_%28image_processing%29 [ ^ ]。



上面的文章参考显示了三个用于模糊的示例内核。你可以创造别的东西。这种转换可以在WPF或 System.Drawing.Bitmap 中完成(您可以从屏幕副本中获取,并且需要转换为WPF位图)。您可以自己访问任何位图的位并执行卷积。只是不要使用过于缓慢的 GetPixel / SetPixel ,而是使用 LockBits System.Drawing )或者,对于WPF,类 WriteableBitmap

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap。 lockbits%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap% 28v = vs.110%29.aspx [ ^ ]。



如果您觉得困难,可以使用,例如充足的开放式AForge.NET库,其卷积类,模糊类,特别是 GaussianBlur

http://www.aforgenet.com/framework/docs/html/3b7d8422-2d79-8019-8933-a0472040c124.htm [ ^ ],

http://www.aforgenet.com/framework/docs/html/be5cfa72-caa1-205b -d282-9abe2fc1c19b.htm [ ^ ],

http://www.aforgenet.com/framework/docs/html/f074e0dd-865c-fd5f-ba0a-80e336a0ea ea.htm [ ^ ]。



您也可以使用您选择的任何矩阵。



除了这个假背景之外,您还可以放置所需的WPF内容。有许多小事需要解决。例如,当您单击假背景窗口时,您需要恢复正常。您需要删除此窗口并激活其后面的真实窗口。等等......



对不起,我的解决方案有点原理图。找出所需的所有部分真的需要很多知识。如果您对这项工作的数量感到害怕,可以尝试开始并提出进一步的问题。



-SA

How I can blur everything that is behind window or for example behind grid? The purpose is not to blur the part of the window, but everything that is behind the window on windows xp and higher. I heard about dwmapi, but this is not working on windows xp. How i can do this?

解决方案

This is not going to be easy. You are going to modify the look not of your window, but the whole desktop with the application window which has nothing to do with your application and, hence, nothing to do with WPF.

Nevertheless, there is a work around. You have to copy the whole desktop image and then create your own WPF window which covers all the background and mimic it. This background window should be a separate top-level window with the property WindowStyle set to System.Windows.WindowStyle.None:
http://msdn.microsoft.com/en-us/library/system.windows.window.windowstyle%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.windowstyle%28v=vs.110%29.aspx[^].

It will allow you creating a window without any non-client area, to cover all the current desktop to mimic the desktop appearance. In this window, you need to draw the graphic copied from the "real" desktop, blurred or the way you want.

There are many ways to capture the screen. You can search a solution on the Web.
You can also look at the source code of this open-source project: http://sourceforge.net/projects/screencapturewp[^].

To create some blur effect (there are way to many different kinds of blur, including very realistic but hard to calculate boke), you can use convolution matrix:
http://en.wikipedia.org/wiki/Kernel_%28image_processing%29[^].

The article reference above shows three sample kernels for blur. You can create something else. This kind of transformation can be done in WPF or System.Drawing.Bitmap (which you can obtain from screen copy and will need to transform to a WPF bitmap). You can access bits of any of those bitmaps by yourself and perform the convolution. Only don't use prohibitively slow GetPixel/SetPixel, instead use LockBits (System.Drawing) or, with WPF, the class WriteableBitmap:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=vs.110%29.aspx[^].

If it seems to difficult for you, you can use, for example, open-sourse AForge.NET library, its Convolution class, Blur class, in particular, GaussianBlur:
http://www.aforgenet.com/framework/docs/html/3b7d8422-2d79-8019-8933-a0472040c124.htm[^],
http://www.aforgenet.com/framework/docs/html/be5cfa72-caa1-205b-d282-9abe2fc1c19b.htm[^],
http://www.aforgenet.com/framework/docs/html/f074e0dd-865c-fd5f-ba0a-80e336a0eaea.htm[^].

You can also use any matrix of your choice.

On top of this "fake background", you can put the WPF content you need. There are many small things to solve. For example, when you click in the "fake background" window, you need to "get back to normal". You need to remove this window and activate the "real" window behind it. And so on…

Sorry that my solution is a bit schematic. It really takes good deal of knowledge to figure out all the pieces you need. If you don't feel scared by the volume of this work, you can try to start and ask further questions as you go.

—SA


这篇关于Windows XP上的Wpf模糊窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆