Exemple #1
0
        /// <summary>
        /// 异步线程池绑定缩略图
        /// </summary>
        private static void BindThumbnialAync(ThumbnailImage image, object fileSource, double w, double h)
        {
            if (fileSource == null)
            {
                return;
            }
            IThumbnailProvider thumbnailProvider = ThumbnailProviderFactory.GetInstance(image.ThumbnailType);
            var cache = image.CacheEnable;
            var time  = image.CacheTime;

            System.Utility.Executer.TryRunByThreadPool(() =>
            {
                ImageSource img = null;
                if (cache)
                {
                    img = CacheManager.GetCache <ImageSource>(fileSource.GetHashCode().ToString(), time, () =>
                    {
                        return(thumbnailProvider.GenereateThumbnail(fileSource, w, h));
                    });
                }
                else
                {
                    img = thumbnailProvider.GenereateThumbnail(fileSource, w, h);
                }
                image.Dispatcher.BeginInvoke(new Action(() => { image.Source = img; }), DispatcherPriority.ApplicationIdle);
            });
        }
Exemple #2
0
        /// <summary>
        /// 属性更改处理事件
        /// </summary>
        private static void OnSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            ThumbnailImage img = sender as ThumbnailImage;

            if (img == null)
            {
                return;
            }
            if (!img.IsLoaded)
            {
                return;
            }
            BindSource(img);
        }
Exemple #3
0
        private static void BindSource(ThumbnailImage image)
        {
            var    w      = image.Width;
            var    h      = image.Height;
            object source = image.ThumbnailSource;

            //bind
            if (image.AsyncEnable)
            {
                BindThumbnialAync(image, source, w, h);
            }
            else
            {
                BindThumbnial(image, source, w, h);
            }
        }