Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitmap manipulation in C++ on Windows

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?

like image 313
Oliver Avatar asked Oct 11 '25 20:10

Oliver


2 Answers

You can use OpenCV library as a full image processing tool.

You can also use MFC's CImage or VCL's TBitmap just to extract pixel values from HBITMAP.

like image 89
Janusz Lenar Avatar answered Oct 14 '25 08:10

Janusz Lenar


Gdiplus::Bitmap* pBitmap = Gdiplus::Bitmap::FromHBITMAP( hBitmap, NULL );
Gdiplus::Color pixel_color;
pBitmap->GetPixel( x, y, &pixel_color ); // read pixel at x,y into pixel_color
// ...
delete pBitmap; // do not forget to delete
like image 42
Kirill V. Lyadvinsky Avatar answered Oct 14 '25 08:10

Kirill V. Lyadvinsky