1

I am running a console application in Visual Studio 2017 RC. When executing the code below I get a System.OutOfMemoryException: 'Out of memory.' exception.

The image im trying to load is a 32-bit float image.
Loading a 16-bit float image works fine.

I have tried setting the Plattform type to x64in the Configuration Manager.

using System.Drawing;

namespace ConsoleAppImageTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string PathToFile = @"D:\img\rgb32bitF.tiff";
            Image img = Image.FromFile(PathToFile);
        }
    }
}
Leander
  • 508
  • 6
  • 21

2 Answers2

1

Try LibTiff.NET for handling TIFF images.

Svekke
  • 1,470
  • 1
  • 12
  • 20
0

This answer provides a solution to opening (32-bit) tiffs (as suggested by M Adeel Khalid).

Add a the PresentationCore reference and using System.Windows.Media.Imaging;.

 string PathToFile = @"D:\img\rgb32bitF.tiff";
 Stream imageStreamSource = new FileStream(PathToFile, FileMode.Open, FileAccess.Read, FileShare.Read);
 TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
 BitmapSource bitmapSource = decoder.Frames[0];
Community
  • 1
  • 1
Leander
  • 508
  • 6
  • 21