user1255454
user1255454

Reputation: 699

HBITMAP/BITMAP to BITMAPINFOHEADER -> over network - > BITMAPINFOHEADER to HBITMAP/BITMAP

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.

Upvotes: 2

Views: 1677

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

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

Upvotes: 7

Related Questions