WPF的Image控件BitmapImage以及Uri的资源占用问题

来源:互联网 发布:域名备案批量查询 编辑:程序博客网 时间:2024/05/18 22:45

Image 控件占用图片资源不释放的问题的解决方法:

XAML:

<Image Name="_imgDisplay" Stretch="Fill" /><dxe:PopupImageEdit                        Name="popupImageEdit" MouseDoubleClick="popupImageEdit_MouseDoubleClick"                        VerticalAlignment="Center"                        Width="300" IsReadOnly="true"                        PopupMaxHeight="400"                        PopupMaxWidth="400"                        ShowMenu="{Binding Path=IsChecked, ElementName=chkShowMenu}"                         Stretch="{Binding Path=EditValue, ElementName=cmbStretch}"                        ShowLoadDialogOnClickMode="{Binding Path=EditValue, ElementName=cmbLoadDialogMode}" />


点击“Edit Image”  调用系统自带绘图工具进行修改

/// <summary>/// 对Image控件上的图片进行修改/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void ImgEdit_Click(object sender, RoutedEventArgs e){string filePath = string.Format("\"{0}\"", ImgPath);// 先释放独占资源ImgOld = null;GC.Collect();System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo();processStartInfo.FileName = "mspaint.exe";// 调用系统自带的绘图工具画图(修改)processStartInfo.Arguments = filePath;Process process = System.Diagnostics.Process.Start(processStartInfo);process.EnableRaisingEvents = true;process.WaitForExit();// 重然加载图片LoadImage();}





保存图片正常



其余部分代码:

private String _imgPath = String.Empty;public String ImgPath{get{return _imgPath;}set{_imgPath = value;OnPropertyChanged("ImgPath");}}private void LoadImage(){ImgPath = @"C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\A4T3S4B74T8E0001.jpg";ImgOld = new BitmapImage(new Uri(ImgPath, UriKind.Absolute));popupImageEdit.Source = ImgOld.Clone();_imgDisplay.Source = ImgOld.Clone();}BitmapImage ImgOld = null;



0 0
原创粉丝点击