title: Writing 16 bit single channel image into Tiff
body: <p>I am trying to save an image in tiff file format. I have used libraw to read the raw data from camera and it gives me unsigned short data. I have done some operation on the data and I want to save the result as a 16 bit grayscale (1 channel) image with Tiff file format. But the result is just a blank image. Even if I use the buffer that keeps the original bayer image it won't save correctly. This is the code that I am using for saving:</p>
  
  <pre><code>// Open the TIFF file
  if((output_image = TIFFOpen("image.tiff", "w")) == NULL){
        std::cerr &lt;&lt; "Unable to write tif file: " &lt;&lt; "image.tiff" &lt;&lt; std::endl;
  }
  
  TIFFSetField(output_image, TIFFTAG_IMAGEWIDTH, width());
  TIFFSetField(output_image, TIFFTAG_IMAGELENGTH, height());
  TIFFSetField(output_image, TIFFTAG_SAMPLESPERPIXEL, 1);
  TIFFSetField(output_image, TIFFTAG_BITSPERSAMPLE, 16);
  TIFFSetField(output_image, TIFFTAG_ROWSPERSTRIP, 1);
  TIFFSetField(output_image, TIFFTAG_ORIENTATION, (int)ORIENTATION_TOPLEFT);
  TIFFSetField(output_image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  TIFFSetField(output_image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  TIFFSetField(output_image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  
  
  // Write the information to the file
  
  tsize_t image_s;
   if( (image_s = TIFFWriteEncodedStrip(output_image, 0, &amp;m_data_cropped[0], width()*height())) == -1)
   {
        std::cerr &lt;&lt; "Unable to write tif file: " &lt;&lt; "image.tif" &lt;&lt; std::endl;
   }
   else
   {
          std::cout &lt;&lt; "Image is saved! size is : " &lt;&lt; image_s &lt;&lt; std::endl;
   }
  
  TIFFWriteDirectory(output_image);
  TIFFClose(output_image);
  </code></pre>