I am transferring a jpg file over a socket, in connection with this I have a char (char *) array, which I received from a socket and do I need to convert this array back to a jpeg image? How to do it? As I understand it, without the libjpeg library I cannot do this?
|
2 answers
If you completely transfer the jpg file to a socket, then you already have an image in char * as a stream, so just save the entire array to a file and PROFIT. And better clarify the question, he does not fully open the question
- Well, then yes, but I do not know all the subtleties, I just have no idea how this will affect the jpg file. Suppose an andorid client written in java sent an image as an array of bytes, I received it as an array char * and saved it without an extension to some file, will the file get corrupted if I consider the array char and return it to the client via a socket? - cvxbcvbsd fsddfgdfg
- If TCP socket then the files do not change during sending, if you save without changing, then you can even open everything and see them - Diaz Suleimenov
- And if any other protocol? - cvxbcvbsd fsddfgdfg
- But the data may change when sending, but if you make some kind of error detection and correction system, the data will not change, many VPN protocols work like this, all protocols that are based on TCP (http, ftp, ssh them) then they are also guaranteed will not be changed due to sending - Diaz Suleimenov
- I use asynchronous advice, I just xs, do the data change before sending with asynchronous sockets? - cvxbcvbsd fsddfgdfg
|
Just write to the file for example, wrote a small piece of code that works fine:
int main(int argc, char **argv) { ifstream file( "jpeg.jpeg", ios::binary ); if (!file) { cerr << "can't open file's" << endl; return 0; } file.seekg(0,ios::end); size_t fSize = (int)file.tellg(); unsigned char * a = new unsigned char[fSize]; if (file.read( (char*)a,fSize )) { ofstream fout ( "def.jpeg", ios::binary ); if (!fout) return 0; fout.write( (char*)a, fSize ) } return 0; }
|