Question: This is part of my program:

```
// let's get jpg image from socket
int iRcvdBytes=recvfrom(iSockFd, buff, bufferSize, 0, 
(struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);

// buff now contains 30KB jpg image

// let's load the jpg image to IplImage
IplImage* fIplImageHeader;
fIplImageHeader = cvCreateImageHeader(cvSize(640, 480), 8, 1);
fIplImageHeader->imageData = (char *)buff;

// now let's check the size difference
cout << "Received " << iRcvdBytes << " bytes from the client" << endl;
cout << fIplImageHeader->imageSize << endl;

```

And the output is:

```
Received 31860 bytes from the client
307200

```

Now why is that? Is cvCreateImageHeader() converting the jpg image to RGB or something like that internally? I want it to stay JPG and show it with cvShowImage().

Please, any help would be welcome.

Answer: 
You are comparing the lenght of the compressed jpeg image data to the uncompressed pixel data.

In particular, given: 

```
fIplImageHeader = cvCreateImageHeader(cvSize(width, height), depth, channels) 

```

It will always be the case that `fIplImageHeader->imageSize` == `width * height * (depth/8) * channels`

Assigning the bytes recieved by the `recvfrom()` call to the `imageData` area doesn't work in the first place.
Jpeg does not represent an exact representation of an image. It's a "lossy" format (i.e. you lose some detail in exchange for a smaller size image). I'd bet you haven't specified the 'quality' of the image you want so it's using a default high quality. Look for a quality setting and set it for a lower value. You'll need to balance quality of image versus file size to suit your application.