如何在WPF图像中加载非常大的源图像?

问题描述 投票:4回答:3

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

我可以使用Windows Photo Viewer观看此图像!

我将我的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都在工作。

我在做什么错?抱歉我的英语不好,谢谢。

wpf image view load
3个回答
3
投票

64-Bit Applications

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


2
投票

我将其分为10(3000x3000)个段,并将它们分成10个文件。

也请检查您使用的格式。它可能正在填充文件大小或特定格式的阈值。尝试TIF格式,然后尝试JPG,然后尝试BMP,等等。另请参阅是否可以将JPG格式压缩为40-50%,并查看是否有任何改变。

让我知道您发现了什么。


1
投票

您可以直接从硬盘显示图片以减少内存使用。

BitmapCacheOption

此示例代码将直接从HDD读取图像,并且根据图像容器的大小,将仅使用小的缩略图。

public BitmapImage memoryOptimizedBitmapRead(string url,FrameworkElement imageContainer)
        {
            if (string.IsNullOrEmpty(url) || imageContainer.ActualHeight<= 0)
            {
                return null;
            }

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

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

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

        }
© www.soinside.com 2019 - 2024. All rights reserved.