title: C# - Image can't be opened in Windows XP but same code works in Windows 7
body: <p>I have two tiff images, one is black and white, the other is grayscale8.</p>
  
  <p>I need to show them in picture box, when I try to open them:</p>
  
  <pre><code>Image.FromFile("path");
  </code></pre>
  
  <p>The BW one opens with no issues, the grayscale one give me an exception: "out of memory"</p>
  
  <p>That only happens when I execute the code in a WinXP SP3 machine, a colleague with a Windows 7 has no problems in both cases</p>
  
  <p>Any ideas?</p>
  
  <p>More info: MS Paint and standard Microsoft Image Viewer can't open the grayscale image, while Office Picture Manager can</p>
  
  <p>Windows 7 can open image with any softwate</p>
  
  <p>I have this temporal solution, but I think is not the best:</p>
  
  <pre><code>System.Windows.Media.Imaging.BitmapImage bImg = null;
  
  using (var fs = new FileStream(dlg.FileName, FileMode.Open))
  {
      bImg = new System.Windows.Media.Imaging.BitmapImage();
      bImg.BeginInit();
      bImg.StreamSource = fs;
      bImg.EndInit();
  }
  
  if (bImg.Format == System.Windows.Media.PixelFormats.Gray8)
  {
      Bitmap bitmap;
  
      using (MemoryStream outStream = new MemoryStream())
      {
          BitmapEncoder enc = new BmpBitmapEncoder();
          enc.Frames.Add(BitmapFrame.Create(bImg));
          enc.Save(outStream);
          bitmap = new System.Drawing.Bitmap(outStream);
      }
      AssignImage(bitmap);
  }
  else
      AssignImage(Image.FromFile(dlg.FileName));
  </code></pre>