|
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;
num=recv(Socket, buff, sizeof(buff), 0);
std::ifstream is;
is.open(buff, std::ios::binary);
is.seekg(0, std::ios::end);
num = is.tellg();
is.seekg(0, std::ios::beg);
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!
|
|
|
|
|
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?
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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?
|
|
|
|
|
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.
|
|
|
|
|
yes exactly this is the thing.
But not getting the exact thing how to do this?
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|