I want to extract the jpg image from an Hex file. The hex file comes from a serial camera that outputs a hex stream in the serial port. I need to reconstruct the image.
The output of the camera is attached in the text file.
the code I'm using reads the hex values and convert them to ASCII and save the file as a .jpg.
When I try to open the "picture.jp g" with Photo Editor it reads the start FFD8 correctly but it can't display the image.
Thanks for your help
The output of the camera is attached in the text file.
the code I'm using reads the hex values and convert them to ASCII and save the file as a .jpg.
When I try to open the "picture.jp g" with Photo Editor it reads the start FFD8 correctly but it can't display the image.
Code:
/**************************************************/
char hexToAscii(char first, char second)
{
char hex[5], *stop;
hex[0] = '0';
hex[1] = 'x';
hex[2] = first;
hex[3] = second;
hex[4] = 0;
return strtol(hex, &stop, 16);
}
/***************************************************/
int main(int argc, char *argv[])
{
ofstream myfile;
string line, line1;
myfile.open ("picture.jpg");
ifstream myfile1 ("foto2_HEX.txt");
if (myfile1.is_open())
{ i=0;
while ( myfile1.good() )
{ getline (myfile1,line);
for (i=0; i < line.length(); i++)
{ ab = hexToAscii(line[i], line[i+1]);
i++;
//cout << ab;
myfile << ab;
}
}
}
myfile.close();
myfile1.close();
system("PAUSE");
return EXIT_SUCCESS;
}
Comment