3

I am trying to convert an image presented as HEX data (comes in as HEX in a XML file) back into an image that I can display using my stack user interface. I have tried every option that I could think of and could find in forums and manuals and ended up with the binaryEncode function: binaryEncode(formatsList,dataStringList) and tried all possible "formatsList" options (e.g. h,H,C,etc.). One example in my stack:

on mouseUp
  put field "Field2" into tHex
  put binaryEncode("x*",tHex) into URL "binfile:/Users/xxx/Desktop/VV/test.png"
end mouseUp

The HEX data is comma separated as per the dictionary and is something like: FF,D8,FF,E0,00,11,4A,46,49,46,00,01,01,01,00,00,00 etc. Any assistance will be appreciated.

Danny
  • 127
  • 6

2 Answers2

3

For reference, here's what you were originally aiming for;

put field "Field2" into tHex
replace comma with empty in tHex
put binaryEncode("H*", tHex) into  URL "binfile:/Users/xxx/Desktop/VV/test.png"
Mark
  • 2,380
  • 11
  • 29
  • 49
splash21
  • 799
  • 4
  • 10
  • He wrote he already tried this. That's why I offered a different approach. – Mark Jun 16 '14 at 14:24
  • Yes, I can read :) He was on the right track with the correct function, but just didn't get it working. The example above works and is far more efficient. – splash21 Jun 16 '14 at 18:56
1

This is a little slow, but it is pretty much guaranteed to work:

repeat for each item myHex in fld "Field2"
  put numToChar("0x" & myHex) after myBinary
end repeat
put myBinary into url "binfile:/Users/xxx/Desktop/VV/test.png"

It converts every hex word into its binary equivalent. If you'd add the line put myBinary to the end, you should recognize the PNG format (if the original image is in PNG format).

On a side note, it is a little dangerous to call a field "Field2". You might easily make a mistake and write "Field 2", which would be a completely different field with number 2 instead of the field with name "Field 2". I'd recommend using slightly more inventive names.

Mark
  • 2,380
  • 11
  • 29
  • 49
  • 1
    Thanks Mark - you are a star !! Yup - that field naming was merely used as quick example. – Danny Jun 15 '14 at 18:12