2

I think the title is very much explanatory but here's a bit more detail what I'm trying to do. Basically say I have a BITMAP loaded in Memory.

I would like to extract the BITMAPINFOHEADER from it and add it to my packet structure which will be transferred over a socket.*

Transferring it is not a problem, but once it arrives I'd like to turn it back into a BITMAP so that I can work with it.

I've been struggling with this and I've searched high and low without any luck. An example and a list of functions I will need to accomplish this would be helpful.

Many thanks. I need this in win32 c++. [no .NET or MFC] Appreciated.

user1255454
  • 669
  • 1
  • 8
  • 18
  • http://stackoverflow.com/questions/3539874/bitmap-transfer-using-winsock-getdibits-and-setdibits http://stackoverflow.com/questions/351464/send-bitmap-with-winsock?rq=1 – marcinj Sep 16 '12 at 12:17

1 Answers1

7

Sender:

  1. You have HBITMAP
  2. Obtain its properties, such as width and height, using GetObject
  3. Use CreateDIBSection to create another HBITMAP of the same resolution 24/32-bit RGB with VOID* pointer which points to raw byte; you will initialize BITMAPINFOHEDER in code - you should already have all data you need by that point
  4. BitBlt from original bitmap into this one
  5. Send your BITMAPINFOHEDER + bytes at helper bitmap data pointer to network (sizeof BITMAPINFOHEDER + BITMAPINFOHEDER::biSizeImage bytes)

Receiver:

  1. Use CreateDIBSection to create bitmap using BITMAPINFOHEDER you received; you are getting again a pointer to raw data
  2. memcpy image data into the memory location under the given pointer or just progressively receive data there
  3. You have HBITMAP again
Roman R.
  • 68,205
  • 6
  • 94
  • 158