title: WIA scanning in a WPF application
body: <p>I'm using WIA 2.0 to scan images from a HP scanner. The problem is that saved TIFFs are around 9MBs big (A4 page at 300dpi, grayscale). I convert WIA's ImageFile that contains scan in TIFF format to BitmapSource like this:</p>
  
  <pre><code>    public static BitmapSource ConvertScannedImage(ImageFile imageFile)
      {
          if (imageFile == null)
              return null;
  
          // save the image out to a temp file
          string fileName = Path.GetTempFileName();
  
          // this is pretty hokey, but since SaveFile won't overwrite, we
          // need to do something to both guarantee a unique name and
          // also allow SaveFile to write the file
          File.Delete(fileName);
  
          // now save using the same filename
          imageFile.SaveFile(fileName);
  
          BitmapFrame img;
  
          // load the file back in to a WPF type, this is just
          // to get around size issues with large scans
          using (FileStream stream = File.OpenRead(fileName))
          {
              img = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
  
              stream.Close();
          }
  
          // clean up
          File.Delete(fileName);
  
          return img;
      }
  </code></pre>
  
  <p>Anybody have an idea how to reduce image size, if possible in-memory (because I have a lsit of scans that you can preview and rotate)? Thanks.</p>