title: convert raw image bytes to multipage tiff using java and vice versa
body: <p>I have a requirement where i have set of base64 strings each string is one tiff file, i need to combine all these base64 strings and provide this full tiff data as base64 string, so end user can create a tiff file from the combined base64 strings.</p>
  
  <p>I tried all the ways shared below but each time in my output tiff only one page is coming but i am passing 2 base64 strings.</p>
  
  <p>Any inputs greatly appreciated.</p>
  
  <p>Iam using this code</p>
  
  <pre><code>  ArrayList al = new ArrayList();
  
  //this is repetative so i am adding all the base64 strings to arraylist
  byte[] imgBytes = Base64.decodeBase64(imageObject.get("image").toString());
                                                                                                    al.add(imgBytes);
  
  //writing all base64 strings to a new tiff file //here it is showing only the first page but in the top i am adding two pages.
  BufferedImage imag=ImageIO.read(new ByteArrayInputStream(toByteArray(al)));
                                                                     ImageIO.write(imag, "tif", new File(processedFilesFolder,"combined.tif"));
  
  
  public static byte[] toByteArray(List&lt;byte[]&gt; bytesList)
  {
      int size = 0;
  
      for (byte[] bytes : bytesList)
      {
          size += bytes.length;
      }
  
      ByteBuffer byteBuffer = ByteBuffer.allocate(size);
  
      for (byte[] bytes : bytesList)
      {
          byteBuffer.put(bytes);
      }
  
      return byteBuffer.array();
  }
  
  
  
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream( ); 
  outputStream.write( data ); // this line is repetative
  byte c[] = outputStream.toByteArray( ); 
  try (OutputStream stream = new FileOutputStream("C:\\Users\\XYZ\\Desktop\\EID_Image_Desktop‌​Scan_mod.tiff")) { stream.write(c); } catch(Exception e){}
  </code></pre>
  
  <p>Regards,
  Meerasaaheb Mohmmad</p>