title: display .raw file image in browser
body: <p>I have a image file in .raw format which is directly read from fingerprint scanner device. We have to display that in a browser using html and javascript. How can we convert the .raw image and display in the browser?</p>
  
  <p><strong>Following is the manual steps I used to convert using online tools</strong></p>
  
  <p>I am able to convert that hex content as .raw file using online converter <a href="http://tomeko.net/online_tools/hex_to_file.php?lang=en" rel="nofollow noreferrer">http://tomeko.net/online_tools/hex_to_file.php?lang=en</a> </p>
  
  <p>and converted raw file can be converted again as jpeg file by <a href="https://www.iloveimg.com/convert-to-jpg/raw-to-jpg" rel="nofollow noreferrer">https://www.iloveimg.com/convert-to-jpg/raw-to-jpg</a> url</p>
  
  <p>Sample file will look like this <a href="https://imgur.com/a/4snUAFL" rel="nofollow noreferrer">https://imgur.com/a/4snUAFL</a></p>
  
  <p>I tried the following code to display hex content in the browser but didnt work.</p>
  
  <pre><code>function hexToBase64(str) {
      return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
  }
  
  var img = new Image();
  img.src = "data:image/jpeg;base64,"+hexToBase64(getBinary());
  document.body.appendChild(img);
  </code></pre>
  
  <p>complete jsfiddle is <a href="http://jsfiddle.net/varghees/79NnG/1334/" rel="nofollow noreferrer">http://jsfiddle.net/varghees/79NnG/1334/</a></p>