I have two tiff images, one is black and white, the other is grayscale8.
I need to show them in picture box, when I try to open them:
Image.FromFile("path");
The BW one opens with no issues, the grayscale one give me an exception: "out of memory"
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
Any ideas?
More info: MS Paint and standard Microsoft Image Viewer can't open the grayscale image, while Office Picture Manager can
Windows 7 can open image with any softwate
I have this temporal solution, but I think is not the best:
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));