C++ 中的位图操作在 Windows 上
我自己有一个在 Windows 上用 C++ 编写的位图的句柄:
HBITMAP hBitmap;
在这个图像上我想做一些图像识别、模式分析之类的事情。在我在大学的学习中,我在 Matlab 中完成了这项工作,根据各个像素的位置很容易获得它们,但我不知道如何在 Windows 下的 C++ 中做到这一点 - 我还没有真正能够做到了解我到目前为止所读到的内容。我见过一些对漂亮的 Bitmap 类的引用,它可以让您 setPixel() 和 getPixel() 之类的东西,但我认为这是 .net 的。
我应该如何将 HBITMAP 变成我可以轻松使用的东西?我需要能够获取 RGBA 信息。是否有库允许我处理数据而无需了解 DC 和 BitBlt 之类的东西?
I have myself a handle to a bitmap, in C++, on Windows:
HBITMAP hBitmap;
On this image I want to do some Image Recognition, pattern analysis, that sort of thing. In my studies at University, I have done this in Matlab, it is quite easy to get at the individual pixels based on their position, but I have no idea how to do this in C++ under Windows - I haven't really been able to understand what I have read so far. I have seen some references to a nice looking Bitmap class that lets you setPixel() and getPixel() and that sort of thing, but I think this is with .net .
How should I go about turning my HBITMAP into something I can play with easily? I need to be able to get at the RGBA information. Are there libraries that allow me to work with the data without having to learn about DCs and BitBlt and that sort of thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 OpenCV 库作为完整的图像处理工具。
您还可以使用 MFC 的
CImage
或 VCL 的TBitmap
只是从HBITMAP
中提取像素值。You can use OpenCV library as a full image processing tool.
You can also use MFC's
CImage
or VCL'sTBitmap
just to extract pixel values fromHBITMAP
.使用 GetPixel 尝试此操作来自 GDI 的强>:
Try this using GetPixel from GDI:
使用:
您将在 ds.dsBm 中获得所需的所有内容(包括像素格式和像素缓冲区地址)。
请参阅文档
With:
you will get all you need (including pixel format and pixel buffer adress) in ds.dsBm.
see the doc