0

I want to store tiff images in a List (more than 100 frames) as bytes. I am using TiffBitmapDecoder to decode the tiff file and converting & storing each frame as bytes in the List. It throws System.OutOfMemoryException in between, I could not handle this!! Is there any way to store the large image in memory? Thanks.

ms = New MemoryStream(File.ReadAllBytes(FilePathName)) tiffbmpdecoderViewerImage = New TiffBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default) For Each frame As BitmapFrame In tiffbmpdecoderViewerImage.Frames ms = New MemoryStream BmpEncoder = New BmpBitmapEncoder BmpEncoder.Frames.Add(frame) BmpEncoder.Save(ms) ByteArrayList.Add(ms.ToArray) //exception Next

SivaKtamilan
  • 423
  • 4
  • 8
  • what is "more than 100 frames" supposed to mean? AFAIK, TIFF files are not animated ... there are no "frames". – specializt Aug 19 '15 at 06:04
  • Besides the impossibility of holding an arbitrarily large number of bitmaps in memory, BMP is certainly not the most compact format, You may save a factor of 10 or more by using a compressed format like JPEG. – Clemens Aug 19 '15 at 06:53
  • a Tiff image can have multipages in it. pls refer http://www.awaresystems.be/imaging/tiff/faq.html – SivaKtamilan Aug 19 '15 at 06:57

1 Answers1

1
  • Short answer : "no"
  • Long answer : no, you cannot exceed your physical memory but if you're compiling for x86 (nostalgia much?) you can extend your available RAM up to 4 GiB : *click. I recommend switching your platform over to x64 .... its about time now, you're 10 years late buddy
  • you could also segment your files and process each of them individually ... there is literally no need for having all of the large images in-memory at the same time
  • here is a microsoft article about x64 migration : *click
Community
  • 1
  • 1
specializt
  • 1,913
  • 15
  • 26
  • thanks @specializt, I tried x64 and works well. But it takes 5GB of RAM for the tiff image having 150+ frames. It would be helpful if you add more comments on your 3rd point. – SivaKtamilan Aug 19 '15 at 07:22
  • apparently you can also disable caching altogether : https://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapcacheoption(v=vs.110).aspx], you're looking for `BitmapCacheOption.None` - of course this will increase loading / processing time massively. If you want to process 5 GB of image data without using your memory you're looking at HOURS of runtime ... I think your data source is flawed, not a single human on this planet is dense enough to create GIGABYTES worth of image data except for astronomical researchers perhaps – specializt Aug 19 '15 at 11:54
  • Physical memory is not relevant in a system that employs virtual memory management (see [Memory Management](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366779.aspx) for an introduction). x86 Server Editions of Windows [support up to 64GB RAM](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366778.aspx). But again, available RAM has no impact on the available virtual address space a process can use. – IInspectable Oct 29 '15 at 22:25
  • A [System.OutOfMemoryException](https://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx) is raised, when a process runs out of virtual address space. The documentation links to this article: [“Out Of Memory” Does Not Refer to Physical Memory](http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx). – IInspectable Oct 30 '15 at 10:53