显示过滤器 C#

发布于 2024-08-24 05:32:34 字数 803 浏览 6 评论 0原文

解释我需要什么有点困难,但我会尝试:

我需要编写应用程序(winform),它将是其背后的图像/其他形式的某种过滤器。但有一个例外 - 所有后面的表单都应该看起来像除了红色(例如)之外的颜色,它必须替换为任何其他指定的颜色,例如白色。

假设我打开了 Windows Word,其中只有几行文本。带有红色和黑色字母。 因此,当我将应用程序放置在该文本之上时,它应该“过滤”红色符号并将其填充为白色。

因此,据我了解此任务:我必须捕捉表单后面的区域,然后对其进行处理(替换颜色),然后在表单主体上绘制此图像。

有解决方案的链接或关键字吗?

UPD:

所以 - 这是我的最终解决方案:

  1. 使表单透明(使用 TransparencyKey 和 BackColor 属性),
  2. 当我们需要更新图片框中的图像时,将图片框放在表单上
  3. - 我们用 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:

  1. do form transparent (using TransparencyKey and BackColor properties)
  2. place picturebox over the form
  3. 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 技术交流群。

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

发布评论

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

评论(2

妄司 2024-08-31 05:32:34

您可以使用以下代码创建桌面快照:

public Bitmap CaptureScreen()
{
    Bitmap b = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
    Graphics g = Graphics.FromImage(b);
    g.CopyFromScreen(0, 0, 0, 0, b.Size);
    g.Dispose();
    return b;
}

将尺寸和位置替换为表单的坐标。这样您就可以获得表单背后内容的位图。然后您可以对该位图进行颜色替换。

请注意,由于 ClearType 等设置和其他抗锯齿机制,您在进行颜色替换时还必须考虑“中间像素”。否则事情会看起来很有趣:-)

you can create a snapshot of the desktop using the following code:

public Bitmap CaptureScreen()
{
    Bitmap b = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
    Graphics g = Graphics.FromImage(b);
    g.CopyFromScreen(0, 0, 0, 0, b.Size);
    g.Dispose();
    return b;
}

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 :-)

雅心素梦 2024-08-31 05:32:34

我不知道这是否可以完成(让我们看看其他人的回答:-)。

您可以获得屏幕设备上下文的句柄,它为您提供屏幕的位图。

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:

  • how do you know that the pixels in your interesting region has changed ?
  • if the region changes, are the changes visible or are they hidden by your own drawing.

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 ?

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