保存和加载图像到IsolatedStorage需要保存两次
发布时间:2020-12-14 02:16:56 所属栏目:Windows 来源:网络整理
导读:我使用codeplex中的 ImageTools来将画布保存为png;但是,当我使用writeableBitmap.SaveJpeg()时,我遇到了同样的问题.因此,问题不在于图像类型,而在于我如何在IsolatedStorage中保存或加载. 当我通过按下保存按钮保存图像时文件存在,但是当我加载图像时,没有任
我使用codeplex中的
ImageTools来将画布保存为png;但是,当我使用writeableBitmap.SaveJpeg()时,我遇到了同样的问题.因此,问题不在于图像类型,而在于我如何在IsolatedStorage中保存或加载.
当我通过按下保存按钮保存图像时文件存在,但是当我加载图像时,没有任何内容出现.如果我将图像保存两次,则图像会加载并正确显示. 以下是我的代码. 保存文件: ExtendedImage myImage = myCanvas.ToImage(); using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStore.FileExists("image.png")) isoStore.DeleteFile("image.png"); using (var fileStream = isoStore.CreateFile("image.png")) { myImage.WriteToStream(fileStream,"image.png"); fileStream.Close(); } } 加载文件 BitmapImage bi = new BitmapImage(); using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStore.FileExists("image.png")) { using (var fileStream = isoStore.OpenFile("image.png",FileMode.Open)) { bi.SetSource(fileStream); this.img.Height = bi.PixelHeight; this.img.Width = bi.PixelWidth; this.img.Source = bi; } } } 解决方法
尝试此代码从isoStore检索图像.这个对我有用.
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (iso.FileExists(string.Format("image.png"))) { string fileName = "image.png"; string filePath = iso.GetType().GetField("m_RootDir",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(iso).ToString() + fileName; } } 您可以将Image的源设置为filePath,访问它时不会有任何问题. 如果这不起作用,那么问题是在保存图像时.您可能必须找到将画布保存为png或jpeg的解决方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 你可以在Windows应用程序中使用asp.net会员提供程序吗?
- 如何从Microsoft Z3获得随机结果?
- Meteor的最基本(“todos”)示例在我的Windows 7上无法正常工
- 如何在脚本中禁用“Windows Genuine Advantage Notificatio
- 在Windows操作系统的文件管理器中集成Azure DevOps Server
- 如何使用MinGW创建微小的PE(Win32)可执行文件
- 2019年云计算将有哪些变化?云计算未来前景
- windows – 从脚本安装.msi,检测安装何时完成
- Windows下docker的安装,将ASP.NET Core程序部署在Linux和D
- dll – 使用C API的“Hello TensorFlow!”
推荐文章
站长推荐
- windows – StretchBlt HALFTONE == BILINEAR用于
- Windows上的Python和vim?
- 清除SQLServer日志的两种方法
- .net – 使用InstallUtil卸载不存在的服务
- 错误 – 在Windows 7中使用“Git Bash Here”时,
- 如何在Windows Server上获取本地连接的IP地址?
- 为什么限制在我的WiX / MSI设置中使用自定义操作
- 在Windows Azure角色中OnStop()方法和Stopping事
- windows-phone-8 – wp8 LonglistSelector Anima
- windows – 带子进程的perl报警
热点阅读