private static void BindSource(FImage img) { var value = img.Source; if (value.IsInvalid()) { return; } if (value.Length == 1) { img.FIcon.Text = value; return; } img.Dispatcher.BeginInvoke(new Action(() => { try { var path = value.TrimStart(' ', '/', '\\'); //如果是相对路径则转换为绝对路径 if (!Path.IsPathRooted(path)) { path = File.GetPhysicalPath(path); } BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(path); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); img.Image.Source = bitmapImage; } catch { } }), DispatcherPriority.ApplicationIdle); }
private static void BindSource(AnimatedGIF gif) { gif.StopAnimate(); if (gif.Bitmap != null) { gif.Bitmap.Dispose(); } object source = gif.GIFSource; if (source == null) { return; } //根据类型处理 string sourcetype = source.GetType().ToSafeString(); if (sourcetype.Contains("System.String")) { //文件路径 string path = source.ToSafeString(); if (path.IsInvalid()) { return; } if (!Path.IsPathRooted(path)) { source = File.GetPhysicalPath(path); } gif.Bitmap = new Bitmap(path); } else if (sourcetype.Contains("System.IO.Stream")) { //io.Stream gif.Bitmap = new Bitmap(source as Stream); } else if (sourcetype.Contains("System.IO.MemoryStream")) { //io.MemoryStream gif.Bitmap = new Bitmap(source as MemoryStream); } else { //无效 throw new Exception("Unsupported Stream"); } GetWidthHeight(gif, ref imgw, ref imgh); gif.BitmapSource = GetBitmapSource(gif.Bitmap, gif.BitmapSource); gif.StartAnimate(); }
private static void BindSource(AnimatedGIF gif) { gif.StopAnimate(); if (gif.Bitmap != null) { gif.Bitmap.Dispose(); } var path = gif.GIFSource; if (path.IsInvalid()) { return; } if (!Path.IsPathRooted(path)) { path = File.GetPhysicalPath(path); } gif.Bitmap = new Bitmap(path); gif.BitmapSource = GetBitmapSource(gif.Bitmap, gif.BitmapSource); gif.StartAnimate(); }