public async void LoadCollectedImages(string path) { if (!Directory.Exists(path)) { path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, path); if (!Directory.Exists(path)) { return; } } var folder = new DirectoryInfo(path); foreach (var item in folder.GetFiles().OrderBy(m => m.CreationTime)) { try { ImageItemsSource.Add(new Image { Source = await Extentions.GetBitmapImage(item.FullName) }); } catch (Exception ex) { App.Log.Error(ex.ToString()); } } }
private async Task <AnimatedGif> GetMainMenuIcon() { AnimatedGif animatedGif; var path = _userConfigution.ImageSetting.MainMenuInfo.Path; if (!File.Exists(path)) { path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, path); if (!File.Exists(path)) { animatedGif = (AnimatedGif)Resources["MainMenuIcon"]; animatedGif.Stretch = Stretch.Fill; return(animatedGif); } } try { var imageSource = await Extentions.GetBitmapImage(path); animatedGif = new AnimatedGif { Source = imageSource, Stretch = Stretch.Fill }; } catch (Exception ex) { App.Log.Error(ex.ToString()); animatedGif = (AnimatedGif)Resources["MainMenuIcon"]; animatedGif.Stretch = Stretch.Fill; } return(animatedGif); }
private async void ReplaceBtn_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog() { CheckPathExists = true, Filter = "所有图片 (*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle)|*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle" + "|ICO 图标格式 (*.ico)|*.ico" + "|GIF 可交换的图形格式 (*.gif)|*.gif" + "|JPEG 文件交换格式 (*.jpg;*.jpeg;*.jfif;*.jpe)|*.jpg;*.jpeg;*.jfif;*.jpe" + "|PNG 可移植网络图形格式 (*.png)|*.png" + "|TIFF Tag 图像文件格式 (*.tif;*.tiff)|*.tif;*.tiff" + "|设备无关位图 (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle" }; var showDialog = dialog.ShowDialog().GetValueOrDefault(); if (!showDialog) { return; } try { var fileFullName = dialog.FileName; var fileName = $"MenuItemIcon{fileFullName.Substring(fileFullName.LastIndexOf('.'))}"; File.Copy(fileFullName, Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, fileName), true); var imageSource = await Extentions.GetBitmapImage(fileFullName); _imageControl.Content = new AnimatedImage.AnimatedGif { Source = imageSource, Stretch = Stretch.Fill, }; _userConfig.ImageSetting.MainMenuInfo.Path = fileName; } catch (Exception ex) { App.Log.Error(ex.ToString()); Extentions.ShowMessageBox("出现错误,更改图像失败!"); } }
private async void AddImagesFromFile(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog() { Multiselect = true, CheckPathExists = true, Filter = "所有图片 (*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle)|*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle" + "|ICO 图标格式 (*.ico)|*.ico" + "|GIF 可交换的图形格式 (*.gif)|*.gif" + "|JPEG 文件交换格式 (*.jpg;*.jpeg;*.jfif;*.jpe)|*.jpg;*.jpeg;*.jfif;*.jpe" + "|PNG 可移植网络图形格式 (*.png)|*.png" + "|TIFF Tag 图像文件格式 (*.tif;*.tiff)|*.tif;*.tiff" + "|设备无关位图 (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle" + "|文件图标 (*.*)|*.*" }; var showDialog = dialog.ShowDialog().GetValueOrDefault(); if (!showDialog) { return; } _controlManager.SelectNone(); _controlManager.ContinuedAddCount = 0; var imageControls = new List <ImageControl>(dialog.FileNames.Length); if (dialog.FilterIndex == 8) { foreach (var filePath in dialog.FileNames) { try { imageControls.Add(PackageImageToControl(new AnimatedGif { Source = Extentions.GetBitmapFormFileIcon(filePath), Stretch = Stretch.Fill }, new Point(0, 0))); } catch (Exception ex) { App.Log.Error(ex.ToString()); Extentions.ShowMessageBox("无法加载文件的图标!"); } } } else { foreach (var file in dialog.FileNames) { try { var imageSource = await Extentions.GetBitmapImage(file); imageControls.Add(PackageImageToControl(new AnimatedGif { Source = imageSource, Stretch = Stretch.Fill }, new Point(0, 0))); } catch (Exception ex) { App.Log.Error(ex.ToString()); Extentions.ShowMessageBox("不支持此格式的图片!"); } } } _controlManager.AddElements(imageControls); }