title: Write Bitmap to a MIME message
body: <p>Edit 2 : from the result I got in my first edit, at the bottom of the post, the issue is somewhere at this line or below : <code>imageEncodedSigneAgent = Base64.encodeToString(byteSigneAgent,Base64.NO_WRAP);</code> "
  /edit.</p>
  
  <p>I tried to write a bitmap in a MIME message, as a Base64 String in PNG format. Sadly, the message is considered as null (windows viewer can't read it, says size is 0kb)</p>
  
  <p>My code : </p>
  
  <pre><code>        Bitmap bitmapSigne = BitmapFactory.decodeFile(fileSigne.getAbsolutePath());
          if (Params.tagFgDebug &amp;&amp; fgDebugLocal){Log.i(Params.tagGen, tagLocal + "createEMLInt - bitmapSigne width = " + bitmapSigne.getWidth());};
          ByteArrayOutputStream baos = new ByteArrayOutputStream(bitmapSigne.getByteCount());  
          if (!bitmapSigne.compress(Bitmap.CompressFormat.PNG, 100, baos)) {
              new TException(tagLocal, "Compress bitmapSign == ", "false");
          }
          byte[] byteSigne = baos.toByteArray(); 
          if (Params.tagFgDebug &amp;&amp; fgDebugLocal){Log.i(Params.tagGen, tagLocal + "createEMLInt - byteSigne size = " + byteSigne.length);};
          String imageEncodedSigne = Base64.encodeToString(byteSigne,Base64.NO_WRAP);
          if (Params.tagFgDebug &amp;&amp; fgDebugLocal){Log.i(Params.tagGen, tagLocal + "createEMLInt - imageEncodedSigne size = " + imageEncodedSigne.length());};
          mime.append(imageEncodedSigne);
          mime.append("\r\n");
  </code></pre>
  
  <p>This does write base64 lines in my MIMI message, but it can't be read and is a bit short maybe. I think it might be metadata around the PNG (from what I read after I decode it). </p>
  
  <p>I tested to save the bitmap directly to a File and it works perfectly : </p>
  
  <pre><code>        // test to retrieve BitMap as PNG
          String signePath2 = Baseline.strSdExternalPath + File.separator + Params.MIF_REP;
          File file = new File(signePath2, "sign.png");
          FileOutputStream fOut = new FileOutputStream(file);
          bitmapSigne.compress(Bitmap.CompressFormat.PNG, 85, fOut);
          fOut.flush();
          fOut.close();
          // test to retrieve BitMap as PNG
  </code></pre>
  
  <p>I correctly get the image I draw previously. </p>
  
  <p>I also tried (idea from another SO question : <a href="https://stackoverflow.com/questions/20621285/converting-bitmap-to-byte-array-to-string-then-all-the-way-back">Converting bitmap to byte array, to string, then all the way back</a>) to reconvert the String to a bitmap and it fails :( </p>
  
  <pre><code>            byte[] newImageBytes = imageEncodedSigne.getBytes();
          // Convert byte[] back to bitmap
          Bitmap bitmapReconverted = BitmapFactory.decodeByteArray(newImageBytes, 0, newImageBytes.length);
          File fileReconverted = new File(signePath2, "signReConverted.png");
          fOut = new FileOutputStream(fileReconverted);
          bitmapReconverted.compress(Bitmap.CompressFormat.PNG, 100, fOut);
          fOut.flush();
          fOut.close();
  </code></pre>
  
  <p>What am I missing here ? Why do I fail to properly retrieve the byte data and get a readable string in base64 ? </p>
  
  <p>Any help appreciate ! </p>
  
  <p>I used Base64.DEFAULT before to no better results. I read several post and the one linked is the closest to what I am trying to do, sadly his issue was with a bad use of 'equalTo'</p>
  
  <p>EDIT  : So I tried to do Bitmap -> bytes[] -> Bitmap and it worked : </p>
  
  <pre><code>Bitmap bitmapReconverted = BitmapFactory.decodeByteArray(byteSigne, 0, byteSigne.length);
          File fileReconverted = new File(signePath2, "signReConverted.png");
          fOut = new FileOutputStream(fileReconverted);
          bitmapReconverted.compress(Bitmap.CompressFormat.PNG, 85, fOut);
          fOut.flush();
          fOut.close();
  </code></pre>
  
  <p>Edit 3 : the MIME result for documentation purpose ! </p>
  
  <pre><code>Content-Type: image/png
  </code></pre>
  
  <p>Content-Disposition: form-data; name="body";filename="20150601.190623_00008_SIGN.PNG" 
  Content-Transfer-Encoding: base64 
  iVBORw0KGgoAAAANSUhEUgAAAOYAAABuCAIAAAC86/hZAAAA</p>