Пример #1
0
        internal static void InitCache()
        {
            var files = Directory.EnumerateFiles(Path.Combine(Global.CurrentDir, Global.CacheDir));

            foreach (string filename in files)
            {
                FileInfo fileInfo = new FileInfo(filename);
                Uri localFileUri = new Uri(filename);
                BitmapImage image = new BitmapImage(localFileUri) { CacheOption = BitmapCacheOption.OnLoad};
                images.Add(image.GetHashCode(), new CacheNode<Uri>((int)fileInfo.Length, localFileUri));
            }
        }
Пример #2
0
    public static void LoadBitmapFromIsoAsync(
              string path,
              Action<BitmapImage> callback)
    {
      ThreadUtil.Execute(() =>
        {
          byte[] raw = StorageIo.ReadBinaryFile(path);
          if (null == raw)
          {
            callback(null);
            return;
          }

          var stm = new MemoryStream();
          stm.Write(raw, 0, raw.Length);
          stm.Seek(0, SeekOrigin.Begin);

          ThreadUtil.UiCall(() =>
            {
              var img = new BitmapImage
              {
                CreateOptions = BitmapCreateOptions.BackgroundCreation
              };

              img.ImageOpened += (x, xe) =>
              {
                callback(img);
                _asyncbmpholder.Remove(img.GetHashCode());
              };
              img.ImageFailed += (x, xe) =>
                {
                  callback(null);
                  _asyncbmpholder.Remove(img.GetHashCode());
                };

              lock (_asyncbmpholder)
              {
                _asyncbmpholder.Add(img.GetHashCode(), img);
              }

              img.SetSource(stm);
            });
        });
    }