jxbma
asked on
How do I get a byte array[] from a bitmap in Windows (unmanaged) C++?
Hi:
I'm working with BITMAPs/HBITMAP/LPBITMAP in a Windows C++ application.
I'm currently loading a bitmap file into an HBITMAP via:
I need to get access to the underlying byte array[] for processing.
How do I get the byte array[] from the BITMAP? (without going to a temp file).
I know I can get access to the buffer by directly reading it from the file (via Bitmap header).
But, clients will be passing a BITMAP.
How do I achieve this?
Thanks,
JohnB
I'm working with BITMAPs/HBITMAP/LPBITMAP in a Windows C++ application.
I'm currently loading a bitmap file into an HBITMAP via:
LPBITMAP lpBitmap = new BITMAP();
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "BitmapFileName", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBECTION);
GetObject(hBitmap, sizeof(BITMAP), lpBitmap);
I need to get access to the underlying byte array[] for processing.
How do I get the byte array[] from the BITMAP? (without going to a temp file).
I know I can get access to the buffer by directly reading it from the file (via Bitmap header).
But, clients will be passing a BITMAP.
How do I achieve this?
Thanks,
JohnB
ASKER
Hey sarabande:
Thanks for the response.
This would work if I was actually dealing with a windows based app with:
I actually have a console based C++ app, so I don't have hDC's at my disposal.
I know that when I have bitmap file, I can go directly against the file and retrieve the byte array.
In this interface, the client app will be passing me a HBMP, from which I can get to a LPBITMAP.
How do I get the byte array from here?
Thanks,
JohnB
Thanks for the response.
This would work if I was actually dealing with a windows based app with:
hdc = GetDC(NULL);
hdcMem = CreateCompatibleDC(hdc);
I actually have a console based C++ app, so I don't have hDC's at my disposal.
I know that when I have bitmap file, I can go directly against the file and retrieve the byte array.
In this interface, the client app will be passing me a HBMP, from which I can get to a LPBITMAP.
How do I get the byte array from here?
Thanks,
JohnB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
see the following sample code http://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx
Sara