2011-09-10 63 views
4

我有一个非常大的图像(600mb)30000x30000并希望将其加载到wpf图像控件中。如何在WPF图像中加载非常大的源图像?

我可以用Windows照片查看器观看此图像!

我将我的testapp设置为64位并使用下面的代码。

var image = new BitmapImage(); 
image.BeginInit(); 

// load into memory and unlock file 
image.CacheOption = BitmapCacheOption.OnLoad; 

image.UriSource = uri; 

image.EndInit(); 

imagecontrol.source = image; 

测试应用程序只显示一个白色的屏幕与这个大的图像。

较小的像100mb和7000x7000正在工作。

我在做什么错? Sry为我的英语不好,并提前感谢。

回答

3

64-Bit Applications

与32位Windows操作系统一样,在64位Windows操作系统上运行64位托管应用程序时,可以创建的对象大小有2GB限制。

+0

确切的问题。400mb tif图像作为图像源.Wpf出现了一个白色的屏幕。没有检测到内存使用情况,通过编译针对特定x64平台的应用程序来解决这个问题,但是为什么?我仍然不明白,为什么? –

2

我会将它分成10个(3000x3000)段并将它们放到10个文件中。

另请检查您使用的格式。它可能会填满文件大小或特定格式的阈值。尝试TIF格式,然后尝试JPG,然后尝试BMP等。另请参阅是否可以使用JPG格式将其压缩到40-50%,然后查看是否会改变任何内容。

让我知道你发现了什么。

+0

THX快速的答案,将尝试明天。我必须在图像中进行测量,所以对我来说最简单的方法是将其作为一个文件加载。 – Andreas

+0

我尝试过其他格式,但不幸的是收效甚微。 – Andreas

+0

那很烂,对不起。如何PNG格式或PSD? – ApolloSoftware

0

不知道为什么你不能加载只有600 MB,而限制是2GB的32位。 在任何情况下,你可以通过这样的转换器减少内存使用:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 
     { 
      var url = values[0] as string; 



      var imageConrol =(Image)values[1]; 
      var container = (FrameworkElement)imageConrol.Parent; 
      if (string.IsNullOrEmpty(url) || container.ActualHeight<= 0) 
      { 
       return null; 
      } 

      var bi = new BitmapImage(); 
      bi.BeginInit(); 

      bi.CacheOption = BitmapCacheOption.None; 
      bi.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; 
        bi.DecodePixelHeight = (int)container.ActualHeight; 
      bi.UriSource = new Uri(url, UriKind.Absolute); 

      // End initialization. 
      bi.EndInit(); 
      bi.Freeze(); 
      return bi; 

     } 

从MSDN

// Create Image Element 
Image myImage = new Image(); 
myImage.Width = 200; 

// Create source 
BitmapImage myBitmapImage = new BitmapImage(); 

// BitmapImage.UriSource must be in a BeginInit/EndInit block 
myBitmapImage.BeginInit(); 
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"); 

// To save significant application memory, set the DecodePixelWidth or 
// DecodePixelHeight of the BitmapImage value of the image source to the desired 
// height or width of the rendered image. If you don't do this, the application will 
// cache the image as though it were rendered as its normal size rather then just 
// the size that is displayed. 
// Note: In order to preserve aspect ratio, set DecodePixelWidth 
// or DecodePixelHeight but not both. 
myBitmapImage.DecodePixelWidth = 200; 
myBitmapImage.EndInit(); 
//set image source 
myImage.Source = myBitmapImage; 

http://msdn.microsoft.com/en-us/library/ms748873.aspx