473,473 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to extract jpg image from hex?

1 New Member
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.jpg" with Photo Editor it reads the start FFD8 correctly but it can't display the image.

Expand|Select|Wrap|Line Numbers
  1. /**************************************************/
  2. char hexToAscii(char first, char second)
  3. {
  4.     char hex[5], *stop;
  5.     hex[0] = '0';
  6.     hex[1] = 'x';
  7.     hex[2] = first;
  8.     hex[3] = second;
  9.     hex[4] = 0;
  10.     return strtol(hex, &stop, 16);
  11. }
  12. /***************************************************/
  13. int main(int argc, char *argv[])
  14. {
  15.     ofstream myfile;
  16.     string line, line1;
  17.     myfile.open ("picture.jpg");
  18.  
  19.     ifstream myfile1 ("foto2_HEX.txt");
  20.     if (myfile1.is_open())
  21.     {   i=0;
  22.         while ( myfile1.good() )
  23.         {   getline (myfile1,line);
  24.             for (i=0; i < line.length(); i++)
  25.             {   ab = hexToAscii(line[i], line[i+1]);
  26.                 i++;
  27.                 //cout << ab;
  28.                 myfile << ab;
  29.             }
  30.         }
  31.     }    
  32.     myfile.close();       
  33.     myfile1.close();  
  34.     system("PAUSE");
  35.  
  36.     return EXIT_SUCCESS;
  37.  
  38. }
  39.  
Thanks for your help
Attached Files
File Type: txt foto2_HEX.txt (7.2 KB, 926 views)
Jan 22 '11 #1
1 8322
donbock
2,426 Recognized Expert Top Contributor
What exactly do you mean by the camera "outputs a hex stream in the serial port"? Do you mean that the camera outputs a hex-ASCII stream (the ascii characters '0'-'9' and 'A'-'F') or do you mean it outputs a binary file?

I suspect the answer is a binary file. If so, then just write the binary data to the file -- get rid of the hexToAscii conversion.
Jan 22 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael Stock | last post by:
Hi all, hopefully someone can tell me how to do this for a web server in C#: We have images in a folder you can't access over the net. So everytime we need to display an image from this folder,...
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
0
by: chandrasena | last post by:
I am willing to extract Image format, Image Version, Image Identification, Image type, Image data format, Compression type etc.., from an image. How can i achieve this in C#. Please Send me the Code.
3
by: saurabhhp | last post by:
Hi, I am facing one problem related to reading of TIFF Image data. I need its image part and put it in any other file. I have used ofstream for new file opening and data redirection. ofstream...
1
by: thepbac | last post by:
Hi . I have a rich text file which contain a bitmap I want extract my bitmap out of the RTF but I can't. Please help me
4
by: lushna | last post by:
help to extract image from url
5
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to...
1
Thekid
by: Thekid | last post by:
Hi, I have an image similar to a clock, with numbers and letters going around in a circle. I need to extract the numbers and letters from the image and have them print out in a straight line and in...
1
by: agarwalsunitadhn | last post by:
hi i am first time using blob files .When i use the blob file to diaplay data it is shown in binary format and i want to diplay that in image format.i am using the following code to extract image...
2
by: Pheddy | last post by:
Hi all! Does anybody know how to write a function or script that saves a image from an external site to a local folder? Is it even possible in Classic ASP? I know what to look for on the site...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.