title: LibTiff.Net convert Tiff object to byte array and back
body: <p>Hi I can’t find sample for convert MULTI PAGE tiff image to byte array.</p>
  
  <p>For convert byte array to Tiff I use this method</p>
  
  <pre><code>    public static Tiff CreateTiffFromBytes(byte[] bytes)
      {
          using (var ms = new MemoryStream(bytes))
          {
              Tiff tiff = Tiff.ClientOpen("in-memory", "r", ms, new TiffStream());
              return tiff;
          }
      }
  </code></pre>
  
  <p><strong>EDITED:</strong></p>
  
  <p>This method convert TIFF image with more pages  to byte Array. I think in this method will be root of problem.</p>
  
  <pre><code>    //imageIn is tif image with 12 pages
      public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
      {       
          using (var ms = new MemoryStream())
          {
              imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
              return ms.ToArray();
          }
      }
  
     public static List&lt;System.Drawing.Image&gt; GetAllPages(System.Drawing.Image multiTiff)
      {
          var images = new List&lt;System.Drawing.Image&gt;();
          var bitmap = (Bitmap)multiTiff;
          int count = bitmap.GetFrameCount(FrameDimension.Page);
  
          for (int idx = 0; idx &lt; count; idx++)
          {
              bitmap.SelectActiveFrame(FrameDimension.Page, idx);
              using (var byteStream = new MemoryStream())
              {
                  bitmap.Save(byteStream, ImageFormat.Tiff);
  
                  images.Add(System.Drawing.Image.FromStream(byteStream));
              }
          }
          return images;
      }
  </code></pre>
  
  <p>After conversion to byte array I lose pages.
  Image from byte array has only one page.</p>
  
  <pre><code>  Image src = Image.FromFile(source);
      //imagesInSource.Count (pages) is 12
      List&lt;Image&gt; imagesInSource = GetAllPages(src);
  
      byte[] imageData = ImageToByteArray(src);
  
      Image  des = ImageConvert.ByteArrayToImage(imageData);
      //imagesInSource.Count (pages) is 1
      List&lt;Image&gt; imagesInDes = GetAllPages(des);
  </code></pre>