显示过滤器 C#
解释我需要什么有点困难,但我会尝试:
我需要编写应用程序(winform),它将是其背后的图像/其他形式的某种过滤器。但有一个例外 - 所有后面的表单都应该看起来像除了红色(例如)之外的颜色,它必须替换为任何其他指定的颜色,例如白色。
假设我打开了 Windows Word,其中只有几行文本。带有红色和黑色字母。 因此,当我将应用程序放置在该文本之上时,它应该“过滤”红色符号并将其填充为白色。
因此,据我了解此任务:我必须捕捉表单后面的区域,然后对其进行处理(替换颜色),然后在表单主体上绘制此图像。
有解决方案的链接或关键字吗?
UPD:
所以 - 这是我的最终解决方案:
- 使表单透明(使用 TransparencyKey 和 BackColor 属性),
- 当我们需要更新图片框中的图像时,将图片框放在表单上
- - 我们用 pictureBox1.Image = null; 替换当前图像,然后刷新表单(this.Refresh()) 并制作新快照,
感谢大家;-)
UPD 2: 示例 http://dl.dropbox.com/u/4486681/result.png
UPD 3: 这里有来源
It's a little hard to explain what I need but i'll try:
I need to write application (winform) which will be some kind of filter to image/other forms behind it. With one exception - all behind form should looks as is except of red (for example) color, which have to be replaced to any other specified color, white for example.
So let's imagine I have opened windows Word with few lines of text. With red and black letters.
So when i place my application above this text - it should "filter" red symbols and fill them to white.
So as i understand this task: i have to snap area behind the form, then process it (replace colors) and after draw this image on my form body.
Any links or keywords for solution?
UPD:
so - this is my final solution:
- do form transparent (using TransparencyKey and BackColor properties)
- place picturebox over the form
- when we need to update image in picturebox - we replace current image with pictureBox1.Image = null;, then refreshing form with (this.Refresh()) and do new snapshot
thanks for all ;-)
UPD 2:
sample http://dl.dropbox.com/u/4486681/result.png
UPD 3:
here are sources
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下代码创建桌面快照:
将尺寸和位置替换为表单的坐标。这样您就可以获得表单背后内容的位图。然后您可以对该位图进行颜色替换。
请注意,由于 ClearType 等设置和其他抗锯齿机制,您在进行颜色替换时还必须考虑“中间像素”。否则事情会看起来很有趣:-)
you can create a snapshot of the desktop using the following code:
Replace the dimensions and position with the coordinates of your form. This way you get a bitmap of what's behind your form. Then you can do the color replacement on that bitmap.
Please note that due to settings like ClearType and other anti-aliasing mechanisms, you have to also take into account "intermediate pixels" when doing the color replacement. Otherwise things will look funny :-)
我不知道这是否可以完成(让我们看看其他人的回答:-)。
您可以获得屏幕设备上下文的句柄,它为您提供屏幕的位图。
HDC dc = GetDC(NULL);
(这是 C++,您必须使用 P/Invoke,或在 C++ 中创建混合模式库)
然后您可以使用过滤过程重绘屏幕区域。
现在问题开始了:
您可以在某处设置一个按钮,暂时隐藏您自己的应用程序,并在重新按下时将其显示出来,并过滤新内容。
祝你好运。能否分享一下用户场景?
I don't know if this can be done at all (let's see what others answer :-).
You can get a handle to the screen device context, which gives you a bitmap of the screen.
HDC dc = GetDC(NULL);
(This is C++, you'll have to use P/Invoke, or create a mixed-mode library in C++)
Then you can redraw a region of the screen with your filtering process.
Now the problems start:
You could have a button somewhere that hides your own app momentarily and shows it back when re-pressed, and filters the new content.
Good luck. Any possibility of sharing the user scenario ?