Click here to Skip to main content
15,883,805 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Dim buff As Byte() = System.IO.File.ReadAllBytes(OpenFileDialog1.FileNames(index))
Dim ms As New System.IO.MemoryStream(buff)
Dim img As System.Drawing.Image
img = Image.FromStream(ms)
ms.Dispose()
Posted
Comments
Bernhard Hiller 23-Sep-14 8:29am    
how big is your image? (in bytes, and also in pixels wide x pixels high)
Kornfeld Eliyahu Peter 23-Sep-14 9:13am    
According to his other post (removed as duplicate) it's about 80 GB...
PhilLenoir 23-Sep-14 9:17am    
Hmm, it's looks like we have the answer! :)
Sergey Alexandrovich Kryukov 23-Sep-14 11:42am    
I even have the advice for big images. A big "virtual image" can be supported, composed on a set of smaller images; so only few small images would be loaded at a time.
Please see Solution 1.
—SA
PhilLenoir 23-Sep-14 9:16am    
The obvious answer is that you don't have enough free memory. Use a performance monitor (Task Manager will do) as you run the code and look at memory usage.

However an old Windows error reporting issue may be at play here. Out of Memory is error zero. If a library didn't implement error handling properly and set the error number Windows would report the error as Out of Memory. This may or may not be the case here. If your memory usage does not exceed the resources, start looking for other problems. Is the file locked? What is the format of the file? Try a file of a different format of the same size ...

You cannot possibly add memory to your system by any software trick. Either have more memory (it may require having 64-bit system, because 32-bit systems are limited by 4Gb of address space, some half or a quarter of it used up by the OS) or reduce your memory consumption.

[EDIT]
See also Solution 2 which corrects my statements about memory limitations.
[END EDIT]

In case of big images, you can always reduce the size of the actually loaded images to some size approximately matching the pixel size of the biggest monitor, or, for convenience and benefits of buffering, some 4-9 of such sizes. For that purpose, you can break you big file in smaller fragment and load them on request. For example, in case when each piece is exactly of the size of the screen, you never need to load more than 4 of such pieces at a time (can you picture that?). And if your area showing the image is always smaller than that, the problem is even easier.

—SA
 
Share this answer
 
v2
I would have a read of this technical blog on Code Project. Memory Limits in a .NET Process[^].

This is taken from the above link

Quote:
Allocation of big objects

Maybe you don’t know it, but all versions of .Net until the last one (1.0, 2.0, 3.0, 3.5 and 4.0) have a limit on the maximum size a single object can have: 2 GB. No matter if you are running in a 64bit or 32bit process, you cannot create anything bigger than that, in a single object. It’s only since version 4.5 when that limit has been removed (for 64 bit processes only). However, besides very few exceptions, you are very likely applying a wrong design pattern to your application if you need to create such a big objects.

In the .Net world, the GC classifies objects into two categories: small, and large objects. Where you expecting something more technical? Yeah, me too… But that’s it. Any object smaller than 85000 bytes is considered small, and any object larger than that is considered large. When the CLR is loaded, the Heap assigned for the application is divided into two parts: the SOH (Small Objects Heap) and the LOH (Large Objects Heap). Each kind of object is stored on it’s correspondent Heap.

It’s also remarkable to say that Large object’s compaction is very expensive, so it’s directly not done in current versions of .Net (developers said that this situation might change in the future). The only operation similar to compaction done with Large objects is that two adjacent dead objects are fused together into a single chunk of free memory, but no Large object is currently moved to reduce fragmentation.

This fantastic article has much more information about the LOH.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Sep-14 13:00pm    
5ed.
I also corrected my Solution 1 by crediting your answer.
—SA
Simon_Whale 23-Sep-14 14:03pm    
Thanks SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900