windows-phone-7 – 尝试绑定隔离存储映像时应用程序崩溃
在我的应用程序中,我使用下面提到的帮助方法将我的独立存储图像绑定到
Image控件.我从链接“
Binding Image stored in the Isolated Storage to Image Control in Windows Phone”获得了这个帮助方法
public class IsoStoreImageSource : DependencyObject { public static void SetIsoStoreFileName(UIElement element,string value) { element.SetValue(IsoStoreFileNameProperty,value); } public static string GetIsoStoreFileName(UIElement element) { return (string)element.GetValue(IsoStoreFileNameProperty); } // Using a DependencyProperty as the backing store for IsoStoreFileName. This enables animation,styling,binding,etc... public static readonly DependencyProperty IsoStoreFileNameProperty = DependencyProperty.RegisterAttached("IsoStoreFileName",typeof(string),typeof(IsoStoreImageSource),new PropertyMetadata("",Changed)); private static void Changed(DependencyObject d,DependencyPropertyChangedEventArgs e) { Image img = d as Image; if (img != null) { var path = e.NewValue as string; SynchronizationContext uiThread = SynchronizationContext.Current; Task.Factory.StartNew(() => { using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStore.FileExists(path)) { var stream = isoStore.OpenFile(path,System.IO.FileMode.Open,FileAccess.Read); uiThread.Post(_ => { var _img = new BitmapImage(); _img.SetSource(stream); img.Source = _img; },null); } } }); } } } 我在ListBox控件中使用它.如果尝试使用默认库图像,一切都将按预期工作.但是,如果我尝试使用大尺寸的图像(通过设备相机拍摄),应用程序会崩溃. 这是我得到的例外 System.Windows.ni.dll中出现“System.OutOfMemoryException”类型的异常,但未在用户代码中处理 堆栈跟踪 在MS.Internal.FrameworkCallbacks.NotifyManagedDebuggerOnNativeOOM()
ListBox中的缓存可能会占用您的内存,这对于较大的图像尤其明显.我不熟悉您发布的帮助方法,但尝试添加此方法.
if (img != null) { BitmapImage bitmapImage = img.Source as BitmapImage; bitmapImage.UriSource = null; img.Source = null; //rest of the code ... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在IIS 8 / Windows 2012上安装IIS 6管理兼容性
- 程序无法启动,因为您的计算机中缺少MSVCR71.dll.尝试重新安
- Windows – VPN无法正常连接
- Windows – 如何使输出显示在Visual Studio 2005的错误列表
- 域名系统 – 需要Windows Server 2008 R2域控制器DNS反向查
- windows-server-2008-r2 – 为什么Windows Update突然失败,
- .net – Dll不复制到bin文件夹
- Windows – 即使使用NTP,Hyper-V机器也可以随时随地消磨时间
- windows-7 – 更改脱机文件的网络路径
- 用于在Windows上将node.js连接到odbc的库?
- windows – 监控硬盘健康状况的最佳策略是什么?
- Azure VM Windows数据磁盘 – 如何知道它是HDD还
- windows-server-2008 – 如何从Windows Server 2
- windows – 如何从DOS批处理命令发送电子邮件?
- windows-server-2012-r2 – 将GPO备份导入其他域
- haskell – Windows中的着色控制台输出
- Win32:如何使用CreateWindowExW()函数创建ListB
- Windows – 标签完成和箭头键在Git Bash的GHCI中
- Windows下Tomcat内存占用过高问题跟踪(ProcessEx
- windows-8 – Windows 8中listview(WinJS)中的动