I get Insufficient Memory when try to load images like 20 Mb in jpg or 200 Mb in bmp
We have a quite huge (~50MB) raster image in our map control.
The solution was to cut the main image into small pieces and load into a Image[,] array.
-------------------------------------
| pic00 | pic01 | | |
-------------------------------------
| pic10 | | | |
pic.png -> -------------------------------------
| | | | |
-------------------------------------
| | | | picnm |
-------------------------------------
You are able to draw this pieces with Graphics.DrawImage(..).
There is only big issue: if you need the whole picture on the screen, the drawing procedure can be slow. A good workaround to save a thumbnail and show that if needed.
I think there may be a setting in the web.config to allow your app to consume more than the default amount of memory. Failing that, create a larger app pool if its a web app.
Also make sure you are dispose()ing resources as soon as possible.
By default, .net doesn't do any fancy tricks to be more efficient with memory. It's not bad per se, but it wont do you any favours.
If you're using WPF you can load a "thumbnail" of the image into memory, which can be a more reasonable resolution:
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.DecodePixelWidth = 100;
bitmapImage.UriSource = new Uri(imageData.Name);
bitmapImage.EndInit();
this.imageControl.Source = bitmapImage;