Converting Hex String to Bmp file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tawanda diza
    New Member
    • Sep 2011
    • 29

    Converting Hex String to Bmp file

    hie Team.

    here is my scenario:

    1. i managed to convert a bmp image file to hex and then sending it to a server.
    see the following code
    Code:
    fp = fopen("\\C\\photo.bmp","rb");
    			fseek(fp,0,SEEK_END); //go to end
    			PicLen = ftell(fp); //get position at end (length)
    			PICBuffer = (byte *)malloc(PicLen); //malloc buffer
    			fseek(fp,0,SEEK_SET); //go to beg.
    			fread(PICBuffer,PicLen,1,fp); //read into buffer
    			fclose(fp);
    			i=0;
    			
    			do
    			{
    				
    				sprintf(temp,"%02x",PICBuffer[i]);
    				strcat(ReqInfo.Pic,temp);
    				i+=1;
    				
    			}
    			while(i<PicLen);
    2. now the server is returning back those hex values and i want to convert them back to the original bmp image file.



    Thanks in advance
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Do you really know how you converted from BMP to Hexa value??

    Extracting will be follow the same rule

    Comment

    • tawanda diza
      New Member
      • Sep 2011
      • 29

      #3
      johny10151981:

      yes i do. I am actually converting it back to a BMP image, but my picture doesnt look good at all, when i compare the hex values of my original picture and the one i create when i convert from hex to BMP, there is this "D0D0" in my converted output picture.

      i think im not writinhg it correctly:

      see illustration below, i have extractracted the first few hex values for the two pictures:

      original picture hex values:
      FFD8FFE000104A4 649460001010000 0100010000FFDB0 04300100B0C0E0C 0A100E0D0E12111 01318281A181616 183123251D283A3 33D3C3933383740 485C

      my converted picture hex values:
      FFD8FFE000104A4 649460001010000 0100010000FFDB0 04300100B0C0E0C 0D0D0A100E0D0E121110 1318281A1816161 83123251D283A33 3D3C39

      can you see the D0D0 values in the second one.

      thanks

      Comment

      Working...