Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello all!
I'm working on a program in which, I'm receiving the bytes of an image and after storing this creating a bitmap to display.
This is my Main code Please see this..
C++
static char buff[MAX_SIZE];
	int num;
			
//receiving the bytes from a client		 
          num=recv(Socket, buff, sizeof(buff), 0);

		 
    // progress the buffer
  
				

					tagBITMAPFILEHEADER bfh = *(tagBITMAPFILEHEADER*)buff;
					tagBITMAPINFOHEADER bih = *(tagBITMAPINFOHEADER*)(buff+sizeof(tagBITMAPFILEHEADER));

					RGBQUAD             rgb = *(RGBQUAD*)(buff+sizeof(tagBITMAPFILEHEADER)+sizeof(tagBITMAPINFOHEADER));


					BITMAPINFO bi;
bi.bmiColors[0] = rgb;
bi.bmiHeader = bih;
char* pPixels = (buff+bfh.bfOffBits);

char* ppvBits;


hbitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**) &ppvBits, NULL, 0);
SetDIBits(NULL, hbitmap, 0, bih.biHeight, pPixels, &bi, DIB_RGB_COLORS);

GetObject(hbitmap, sizeof(BITMAP), &cBitmap);


I'm unable to create a bitmap from the data received..
I think something wrong with code.

Thanks in advance for your help!
Posted
Updated 1-Feb-13 1:18am
v3
Comments
Matthew Faithfull 1-Feb-13 5:58am    
You're going to need to indicate what is wrong in order to get some help.
Does it compile? Does it run? Do you get a result? What doesn't work?
CPallini 1-Feb-13 6:04am    
And... Where is the question?
Sachin k Rajput 1-Feb-13 6:10am    
its there...

On checking the bytes received,,its ok to be there from both client and server side, But my code is unable to read these bytes to create a bitmap. That's the problem. Connection is OK. Compilation is OK. Have you any idea for this code?
Sachin k Rajput 1-Feb-13 6:06am    
On checking the bytes received,,its ok to be there from both client and server side,
But my code is unable to read these bytes to create a bitmap.
That's the problem.
Connection is OK.
Compilation is OK.
Have you any idea for this code?
Matthew Faithfull 1-Feb-13 6:16am    
OK so I'm guessing you get a blank bitmap or one filled with rubbish?
You're offsets into the recieved data could be wrong or there could be extra headers, missing headers. If all that's wrong is the data then I'm afraid without knowing what data is in your stream I can't help further.

1 solution

read the docs carefully: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx[^]

You better code with a clear and known sample image, and check whether the header and data are transmitted and retreived corectly.

My tip is, that the backcast goes wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900