简体   繁体   English

在WPF / Surface SDK的图像控件中加载高分辨率图像

[英]Loading high resolution images in image control for WPF/Surface SDK

I have a list of high-resolution images obtained from a web server. 我有从Web服务器获得的高分辨率图像的列表。 I need to populate them in the surface SDK scatterview item. 我需要在Surface SDK scatterview项目中填充它们。 To show the images I am using Image control for each image. 为了显示图像,我对每个图像使用图像控件。

Code Logic: 代码逻辑:
User has identity tags which being placed on the surface table will fetch a list of high-resolution images associated with that tag. 用户具有放置在桌面上的身份标签,该身份标签将获取与该标签关联的高分辨率图像的列表。 The fetching of the images is run in background to avoid jamming the UI. 图像的获取在后台运行,以避免卡住UI。 The code to obtain JPEG images in the background is 在后台获取JPEG图像的代码是

public BitmapSource FetchImage(string URLlink)
    {
        JpegBitmapDecoder decoder = null;
        BitmapSource bitmapSource = null;
        try
        {
            decoder = new JpegBitmapDecoder(new Uri(URLlink, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
        }
        catch (Exception)
        {
            decoder = new JpegBitmapDecoder(new Uri("pack://application:,,,/Resources/ImageNotFound.jpg", UriKind.RelativeOrAbsolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand);
        }
        finally
        {
            bitmapSource = decoder.Frames[0];
            bitmapSource.Freeze();
        }
        return bitmapSource;
    }

The images are downloaded from the server and displayed in the image control. 图像从服务器下载并显示在图像控件中。 However, there is severe performance hit and application just hangs when more than 10 images are loaded. 但是,会严重影响性能,并且加载超过10张图像时,应用程序会挂起。 For low-resolution images, i can load even 20-30 images without hanging or slowing down the application. 对于低分辨率图像,我什至可以加载20-30张图像而不会挂起或拖慢应用程序。

Since i read the default algorithm for image control is Fant, I tried chaning the rendering properties to HighQuality. 由于我读取的图像控制默认算法为Fant,因此尝试将渲染属性更改为HighQuality。 Application still hangs, but any lower than this kills the whole idea of having a high-resolution image for display. 应用程序仍然挂起,但任何低于此值的应用程序都将扼杀拥有用于显示的高分辨率图像的整个想法。

RenderOptions.SetBitmapScalingMode(mic.ItemImage, BitmapScalingMode.HighQuality);

Is there a better way of loading images. 有没有更好的方式加载图像。 I was thinking of first saving images to hard-disk and then loading to image source. 我正在考虑先将图像保存到硬盘,然后再加载到图像源。 Would that be effective in improving performance because I was thinking when I am loading images directly from URL it would store it in memory which eventually runs out. 这样对提高性能有效吗,因为我在考虑直接从URL加载图像时会将其存储在内存中,最终用完。 By saving images first I might avoid this, but there might a chance .NET actually is doing the same thing of storing first in temp file and then loading. 通过首先保存图像,我可能会避免这种情况,但是.NET实际上可能会执行相同的操作,即先将其存储在临时文件中,然后再加载。

I also tried changing the BitmapCacheOption to all the available options but it didn't improve anything. 我还尝试将BitmapCacheOption更改为所有可用选项,但并没有任何改善。

The scatterView can not gother a lot of images. scatterView无法处理很多图像。 for exemple try to populate it with 1000 rectangle with one single color. 例如,尝试用一种单色的1000矩形填充它。 It will slow the application . 这会使应用程序变慢。 the problem can not be resolved ,Microsoft have to recode the ScatterView. 无法解决该问题,Microsoft必须重新编码ScatterView。 However you can desactivate some effects on the scatterView. 但是,您可以取消激活scatterView上的某些效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM