windows-phone-7 – System.OutOfMemoryException同时从隔离存储
发布时间:2020-12-14 04:05:12 所属栏目:Windows 来源:网络整理
导读:这是我用于在XAML中绑定图像的代码 Border toolkit:TiltEffect.IsTiltEnabled="true" Height="350" Width="400" Grid.ColumnSpan="3" Grid Height="350" Width="400" Margin="70,70,0" x:Name="Container1" Grid.Background ImageBrush ImageSource="{Bindin
这是我用于在XAML中绑定图像的代码
<Border toolkit:TiltEffect.IsTiltEnabled="true" Height="350" Width="400" Grid.ColumnSpan="3"> <Grid Height="350" Width="400" Margin="70,70,0" x:Name="Container1"> <Grid.Background> <ImageBrush ImageSource="{Binding ImageCollection[0]}" Stretch="Uniform" AlignmentX="Left" AlignmentY="Center"/> </Grid.Background> <i:Interaction.Triggers> <i:EventTrigger EventName="Tap"> <i:InvokeCommandAction Command="{Binding ImageTapCommand}" CommandParameter="CONTAINER0"/> </i:EventTrigger> </i:Interaction.Triggers> </Grid> </Border> 同样我使用4边框显示我最近的图像. 在我的ViewModel中,我使用以下方法从隔离存储中读取图像. public Stream GetFileStream(string filename,ImageLocation location) { try { lock (SyncLock) { if (location == ImageLocation.RecentImage) { filename = Constants.IsoRecentImage + @"" + filename; } using (var iSf = IsolatedStorageFile.GetUserStoreForApplication()) { if (!iSf.FileExists(filename)) return null; var fs = iSf.OpenFile(filename,FileMode.Open,FileAccess.Read); return fs; } } } catch (Exception ex) { return null; } } 在获得流之后,我将使用下面编写的方法四构建用于UI绑定的WritableBitmap private WriteableBitmap BuildImage(Stream imageStream) { using (imageStream) { var image = new BitmapImage(); image.SetSource(imageStream); return new WriteableBitmap(image); } } 在这种情况下,我的问题是在我的页面导航和导出两到三次之后.应用程序在BuildImage()方法崩溃,我正在使用“image.SetSource(imageStream);”方法.我尝试了很多替代品,但失败了我得到的例外是“System.OutOfMemoryException” 我尝试使用Image控件而不是Image画笔. 我尝试过Bitmap而不是WritableBitmap等,但结果是一样的. 如果我使用小图片,应用程序崩溃率将降低.但是通过相机拍摄的图像的崩溃率很高. 我正在尝试解决这个问题的最后一周,但没有找到任何替代方案来解决这个问题. 我找到了一个谈论类似问题的link但是没有多少人来解决这个问题 Try this,var bitmapImage = new BitmapImage(); bitmapImage.SetSource(stream); bitmapImage.CreateOptions = BitmapCreateOptions.None; var bmp = new WriteableBitmap((BitmapSource) bitmapImage); bitmapImage.UriSource = (Uri) null; return bmp; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Microsoft Azure,Webjob,如果我使用cron表达式安排webjob在
- windows-server-2008 – 我可以在Windows 2003服务器上安装
- ARM版本的Windows 8只能运行Metro(WinRt)风格的应用程序吗?
- windows – 如何杀死当前正在运行的所有批处理文件
- windows-7 – 虚拟机客户优化提示
- 更改Windows密码策略
- win10下安装jdk1.8
- 如何检测Windows是否通过LAN或WiFi通过C#
- windows-server-2003 – 更改Microsoft Windows DNS服务器上
- windows – 如何连接Azure存储以从blob存储中读取.txt文件
推荐文章
站长推荐
- Windows – 允许DHCP客户端在域服务器关闭时使用
- 如何使用REST Api在Windows Azure中列出管理证书
- windows-7 – 通过powershell设置接口的MTU
- windows-7 – Windows 7包含重复的,相同的内置打
- 安装 – 使用InstallUtil安装.NET Windows服务时
- 如何在Windows下创建一个md文件
- windows-server-2008 – 在Windows Server 2008
- windows – 无法完全删除git存储库
- Windows – 无法从GitBash运行TASKKILL
- 远程调试作为Windows服务启动的Java应用程序
热点阅读