I get Insufficient Memory when try to load images like 20 Mb in jpg or 200 Mb in bmp
当我尝试在jpg中加载20 Mb或在bmp中加载200 Mb的图像时,我得到内存不足
3 个解决方案
#1
We have a quite huge (~50MB) raster image in our map control.
我们的地图控件中有一个非常大(~50MB)的光栅图像。
The solution was to cut the main image into small pieces and load into a Image[,] array.
解决方案是将主图像切割成小块并加载到Image [,]数组中。
-------------------------------------
| pic00 | pic01 | | |
-------------------------------------
| pic10 | | | |
pic.png -> -------------------------------------
| | | | |
-------------------------------------
| | | | picnm |
-------------------------------------
You are able to draw this pieces with Graphics.DrawImage(..).
您可以使用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.
只有一个大问题:如果您需要在屏幕上显示整个图片,绘图过程可能会很慢。保存缩略图并在需要时显示的良好解决方法。
#2
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.
我认为web.config中可能有一个设置允许你的应用程序消耗超过默认的内存量。如果失败了,如果它是一个Web应用程序,则创建一个更大的应用程
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.
默认情况下,.net不会做任何花哨的技巧来提高内存的效率。它本身并不坏,但它不会对你有任何好处。
#3
If you're using WPF you can load a "thumbnail" of the image into memory, which can be a more reasonable resolution:
如果你正在使用WPF,你可以将图像的“缩略图”加载到内存中,这可以是更合理的分辨率:
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.DecodePixelWidth = 100;
bitmapImage.UriSource = new Uri(imageData.Name);
bitmapImage.EndInit();
this.imageControl.Source = bitmapImage;
#1
We have a quite huge (~50MB) raster image in our map control.
我们的地图控件中有一个非常大(~50MB)的光栅图像。
The solution was to cut the main image into small pieces and load into a Image[,] array.
解决方案是将主图像切割成小块并加载到Image [,]数组中。
-------------------------------------
| pic00 | pic01 | | |
-------------------------------------
| pic10 | | | |
pic.png -> -------------------------------------
| | | | |
-------------------------------------
| | | | picnm |
-------------------------------------
You are able to draw this pieces with Graphics.DrawImage(..).
您可以使用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.
只有一个大问题:如果您需要在屏幕上显示整个图片,绘图过程可能会很慢。保存缩略图并在需要时显示的良好解决方法。
#2
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.
我认为web.config中可能有一个设置允许你的应用程序消耗超过默认的内存量。如果失败了,如果它是一个Web应用程序,则创建一个更大的应用程
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.
默认情况下,.net不会做任何花哨的技巧来提高内存的效率。它本身并不坏,但它不会对你有任何好处。
#3
If you're using WPF you can load a "thumbnail" of the image into memory, which can be a more reasonable resolution:
如果你正在使用WPF,你可以将图像的“缩略图”加载到内存中,这可以是更合理的分辨率:
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.DecodePixelWidth = 100;
bitmapImage.UriSource = new Uri(imageData.Name);
bitmapImage.EndInit();
this.imageControl.Source = bitmapImage;