WPF:使用VB.NET(不使用GDI)获取像素

发布于 2024-12-18 01:44:08 字数 240 浏览 1 评论 0原文

我正在开发一个 WPF 应用程序,我希望检索屏幕上像素的颜色值(屏幕是我的应用程序正在显示的窗口)。

我找到了一个教程,展示了如何使用 gdi32 API 来执行此操作,但由于这是一个 WPF 应用程序,我正在寻找一种不使用 GDI 来执行此操作的方法。

我还找到了如何使用 CroppedBitmap 从图片中检索像素的示例;但是,我没有在我的应用程序中使用图像。

有谁知道如何实现这一目标?

谢谢!

I am working on a WPF application and I am looking to retrieve the color value of a pixel on the screen (the screen being the Window that my application is displaying).

I have found a tutorial that shows how to do this using the gdi32 API but since this is a WPF application I am looking for a way to do this without using GDI.

I have also found an example of how to retrieve a pixel from within a picture using a CroppedBitmap; however, I'm not using an image in my application.

Does anyone know how to achieve this?

Thanks!

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

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

发布评论

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

评论(1

无名指的心愿 2024-12-25 01:44:08

完全披露:我为 WriteableBitmapEx 开源项目做出了贡献,但它不是我的库,也不隶属于其所有者

我知道在普通 WPF 中执行此操作的唯一方法是使用 RenderTargetBitmap将画布渲染为位图,然后使用 WriteableBitmap API 获取指向相关像素的指针。这将是一个非常慢的操作,因为渲染操作涉及创建临时(软件)表面,但是它适合不频繁的操作,例如绘制“颜色选择器”类型的应用程序。

另请参阅 WriteableBitmapEx 库,因为它具有 GetPixel 和 SetPixel 函数,这将在本示例中为您提供帮助。

Full Disclosure: I have contributed to the WriteableBitmapEx open source project, however it is not my library nor am I affiliated with its owner

The only way that I know to do this in vanilla WPF is to use RenderTargetBitmap to render the canvas to a bitmap, then use the WriteableBitmap API to get a pointer to the pixel in question. This will be a very slow operation as the render operation involves creation of a temporary (software) surface, however it would be suitable for infrequent operations, such as paint "color picker" type applications.

Also see the WriteableBitmapEx library, as this has functions for GetPixel and SetPixel which will help you in this example.

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