WPF中的脱机映像缓存 [英] Offline Image Cache in WPF

查看:68
本文介绍了WPF中的脱机映像缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个WPF应用程序,其中  从URL加载图片 当有互联网连接& 
应从缓存中加载这些图像
  ;每当没有活跃的互联网连接时。



我的  问题 是 - 图像未被缓存以显示在后续应用程序启动中
没有任何活动的互联网连接。



我搜索了几个小时,并尝试了几乎所有可能的组合  CreateOptions  &  CacheOption
,但结果有问题。



XAML代码是这样的:

 

<图片
宽度=" {Binding FOOD_TILE_W}" MaxWidth =" 380"
Height =" {Binding FOOD_TILE_H} " MaxHeight =" 240"
Stretch =" UniformToFill">

< Image.CacheMode>
< BitmapCache EnableClearType =" False"
RenderAtScale =" 1"
SnapsToDevicePixels =" False" />
< /Image.CacheMode>

< Image.Source>
< ; BitmapImage UriSource =" {Binding ImageUrl}"
CreateOptions =" IgnoreImageCache"
CacheOption =" OnLoad" />
< /Image.Source>

< / Image>





除了"绑定"代码之外,没有其他C#代码。


是否有可能要实现我的目标?如果是,请怎么样?

解决方案

嗨Touhid,


BitmapImage  自动
默认缓存远程图像。最好与 
CreateOptions =" BackgroundCreation"   for
the best performance。

< Image Height =" 100" Width =" ; 100" Margin =" 12,0,9,0"> 
< Image.Source>
< BitmapImage UriSource =" {Binding ImgURL}" CreateOptions =" BackgroundCreation" />
< /Image.Source>
< / Image>

更详细的信息,请看一下:


https://stackoverflow.com/questions/17261114/image-source -and-caching / 17278222


最好的问候,


樱桃


I have a WPF app, which loads images from URL when there's internet connection & should load those images from cache whenever there's no active internet connection.

My problem is - images are not being cached to show in subsequent app-launches without any active internet connection.

I have searched for hours & tried almost all possible combinations of CreateOptions & CacheOption, but with the same problematic result.

The XAML code is like this:

                

             <Image
                   Width="{Binding FOOD_TILE_W}" MaxWidth="380" 
                   Height="{Binding FOOD_TILE_H}" MaxHeight="240" 
                   Stretch="UniformToFill">

                    <Image.CacheMode>
                        <BitmapCache  EnableClearType="False"
                              RenderAtScale="1"
                              SnapsToDevicePixels="False" />
                    </Image.CacheMode>

                    <Image.Source>
                        <BitmapImage UriSource="{Binding ImageUrl}" 
                             CreateOptions="IgnoreImageCache"
                             CacheOption="OnLoad"/>
                    </Image.Source>

                </Image>


There's no more C# code, except the `Binding` codes of course.

Is it possible to achieve what I am trying? If yes, please how?

解决方案

Hi Touhid,

BitmapImage automatically caches remote images by default. It's best used in conjunction with CreateOptions="BackgroundCreation" for the best performance.

<Image Height="100" Width="100" Margin="12,0,9,0">
  <Image.Source>
    <BitmapImage UriSource="{Binding ImgURL}" CreateOptions="BackgroundCreation"/>
  </Image.Source>
</Image>

More detailed info, please take a look:

https://stackoverflow.com/questions/17261114/image-source-and-caching/17278222

Best Regards,

Cherry


这篇关于WPF中的脱机映像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆