Click here to Skip to main content
       

C / C++ / MFC

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionBitmap creation from a buffer recivedmembertoms from newdelhi1 Feb '13 - 0:03 
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..
 
static char buff[MAX_SIZE];
	int num;
			
//receiving the bytes from a client		 
          num=recv(Socket, buff, sizeof(buff), 0);
 
		 
    // progress the buffer
  
				//ifstream creation	
				std::ifstream is;
 
					is.open(buff, std::ios::binary);
					is.seekg(0, std::ios::end);
					num = is.tellg();
					is.seekg(0, std::ios::beg);
					 
 
					//reading buffer
					is.read(buff, num);
 
					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);
	
 
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.
 
Thanks in advance for your help!
AnswerRe: Bitmap creation from a buffer recivedmvpRichard MacCutchan1 Feb '13 - 0:40 
You only perform a single recv() on your socket; how do you know that you have received all the data? Also, what is the purpose of the ifstream in the above code?
GeneralRe: Bitmap creation from a buffer recivedmembertoms from newdelhi1 Feb '13 - 0:56 
ifstream is to read buffer to create a bitmapinfo.
and if all the data is not received then there should be something on window. either black or something else but there is no activity.
GeneralRe: Bitmap creation from a buffer recivedmvpRichard MacCutchan1 Feb '13 - 1:01 
toms from newdelhi wrote:
fstream is to read buffer to create a bitmapinfo.
Read what buffer? Where is the actual bitmap data that you are reading? Assuming the client is sending this as a binary stream from the original bitmap buffer there should be no work to do at the server end other than ensuring you capture the entire buffer.
GeneralRe: Bitmap creation from a buffer recivedmembertoms from newdelhi1 Feb '13 - 1:18 
yes I got it...
ifstream is basically for a file and not for a binary data.
but how to recv all data and create a bitmap with this...
Are you having any idea?
GeneralRe: Bitmap creation from a buffer recivedmvpRichard MacCutchan1 Feb '13 - 1:35 
toms from newdelhi wrote:
ifstream is basically for a file and not for a binary data.
What does this have to do with your problem?
 
As I understand it you are trying to transfer a bitmap from one computer to another via a network socket. So it is just a matter of transferring the binary data without any changes to its structure, and displaying the bitmap on the target system.
GeneralRe: Bitmap creation from a buffer recivedmembertoms from newdelhi1 Feb '13 - 1:46 
yes exactly this is the thing.
But not getting the exact thing how to do this?
GeneralRe: Bitmap creation from a buffer recivedmvpRichard MacCutchan1 Feb '13 - 2:35 
toms from newdelhi wrote:
yes exactly this is the thing. But not getting the exact thing how to do this?
Too many things here. What exactly do you not understand about transferring a stream of bytes from one PC to another through network sockets? You can find plenty of samples via a Google search.
GeneralRe: Bitmap creation from a buffer recivedmemberjibesh1 Feb '13 - 8:03 
either you need to have a protocol implementation in your Clien-Server communication or you have to make sure that you send all the buffer at one time. If you are choosing a protocol means you first send a message to the server that am going to send a image buffer with size/length X and at the server store this and use this value for the next receive command.
 
If you are going to use whole buffer at one time, just use that buffer as such to create re-create your image. having a protocol is the best choice. if you google you can find many protocols choose the simplest one that suits your requirement.
Jibesh V P

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid