title: How to convert an image(BYTE*) to Base64
body: <p>I have captured a fingerprint image in imgBuffer.</p>
  
  <pre><code>BYTE *imgBuffer = new BYTE[m_ImageWidth*m_ImageHeight];
  myObj-&gt;GetImage(imgBuffer);
  </code></pre>
  
  <p>Convert it into Base64.</p>
  
  <pre><code>int imgBufferSize = sizeof(imgBuffer) - 1;
  QByteArray temp = QByteArray(*imgBuffer, imgBufferSize);
  QByteArray base64Image = temp.toBase64();
  </code></pre>
  
  <p>But I am getting something like this:</p>
  
  <pre><code> BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBw==
  </code></pre>
  
  <p>I followed this: <a href="https://stackoverflow.com/questions/8396620/how-to-convert-an-array-into-qbytearray">How to convert an array into QByteArray?</a></p>
  
  <p><strong>Edit:</strong>
  Actually after implementing Jacob's solution I got another Base64 string but that was not also an image. Though Jacob's solution was correct. The problem was that the image didn't have any meta data. So, I solved it using following procedure:</p>
  
  <pre><code>QImage jpgImage((const unsigned char*)imgBuffer, m_ImageWidth, m_ImageHeight, QImage::Format_Grayscale8);
  
  QByteArray mImage64ByteArray;
  QBuffer buffer(&amp;mImage64ByteArray);
  buffer.open(QIODevice::WriteOnly);
  jpgImage.save(&amp;buffer, "JPG");
  mImage64ByteArray = mImage64ByteArray.toBase64();
  </code></pre>