六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 142|回复: 0

Windowphone访问网络图片-本地缓存-封装CacheNetworkFile.dll的学习

[复制链接]

升级  68%

48

主题

48

主题

48

主题

秀才

Rank: 2

积分
152
 楼主| 发表于 2012-12-22 02:44:16 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">这篇博文是我根据一个缓存网络图片的demo的学习总结。
在这个例子中调用的是CacheNetworkFile.dll中的CacheNetworkImageConvert来进行缓存网络图片的。这个CacheNetworkFile.dll里面到底是什么东东呢?
经过神器Reflector的分析原来如此呀

类CacheNetworkImageConvert实现了IvalueConverter接口
<div class="cnblogs_code" >View Code <div id="cnblogs_code_open_632403e8-e6c6-44d8-9ac4-b976fa08036a" class="cnblogs_code_hide">public class CacheNetworkImageConvert : IValueConverter{    // Methods    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)    {        Uri uri;        BitmapImage2 image;        if (value != null)        {            uri = null;            if (value is string)            {                uri = new Uri((string) value);                goto Label_0030;            }            if (value is Uri)            {                uri = (Uri) value;                goto Label_0030;            }        }        return null;    Label_0030:        image = new BitmapImage2();        CacheNetworkdFile.AddBind(uri, image, BitmapImage2.Source);//调用CacheNetWorkFile的Addbind方法来保存File        return image;    }    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)    {        throw new NotImplementedException();    }    // Nested Types    private class BitmapImage2 : BitmapSource    {        // Fields        public static DependencyProperty Source = DependencyProperty.Register("Source", typeof(Stream), typeof(CacheNetworkImageConvert.BitmapImage2), new PropertyMetadata(null, new PropertyChangedCallback(null, (IntPtr) SourceChanged)));        // Methods        private static void SourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)        {            ((CacheNetworkImageConvert.BitmapImage2) d).SetSource((Stream) e.get_NewValue());            ((Stream) e.get_NewValue()).Dispose();        }    }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表