windows-phone-7.1 – 将照片保存到课堂
我想将CameraCaptureTask中的PhotoResult保存到我作为集合使用的类中,然后保存到隔离存储中:
void cameraCaptureTask_Completed(object sender,PhotoResult e) 这是ObservableCollection的一部分.我想将照片保存到此集合中. [DataMember] public Image VehicleImage { get { return _vehicleImage; } set { if (value != _vehicleImage) { _vehicleImage = value; NotifyPropertyChanged("VehicleImage"); } } } 我正在使用以下示例:http://www.blog.ingenuitynow.net,在该示例中它可以正常工作,但它正在设置一个单独的隔离存储,我只想加入我现有的集合. 我想我不能使用图像类型.什么是完成我希望做的最好的方法? 只是为了回答下面的评论.这就是.Save正在做的: public static void Save<T>(string name,T objectToSave) { using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication()) using (IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(name,System.IO.FileMode.Create,storageFile)) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); serializer.WriteObject(storageFileStream,objectToSave); } }
我想我终于弄清楚了你的问题.在您的ObservableCollection中,我个人不会在那里保留图像.相反,我会保持BitmapSource使用较少的资源,但是您可能有理由为什么你这样做.
我的过程 >将Image.Source(BitmapSource)转换为一个字节[] 保存通用到隔离存储(在我的实用程序类:IsolatedStorage_Utility.cs) public static void Save<T>(string fileName,T item) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(fileName,FileMode.Create,storage)) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); serializer.WriteObject(fileStream,item); } } } 加载通用到隔离存储(在我的实用程序类:IsolatedStorage_Utility.cs) public static T Load<T>(string fileName) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(fileName,FileMode.Open,storage)) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); return (T)serializer.ReadObject(fileStream); } } } 将BitmapSource转换为byte [](在我的实用程序类中:Image_Utility.cs) public static byte[] ImageToByteArray(BitmapSource bitmapSource) { using (MemoryStream stream = new MemoryStream()) { WriteableBitmap writableBitmap = new WriteableBitmap(bitmapSource); Extensions.SaveJpeg(writableBitmap,stream,bitmapSource.PixelWidth,bitmapSource.PixelHeight,100); return stream.ToArray(); } } 将byte []转换为BitmapSource(在我的实用程序类中:Image_Utility.cs) public static BitmapSource ByteArrayToImage(byte[] bytes) { BitmapImage bitmapImage = null; using (MemoryStream stream = new MemoryStream(bytes,bytes.Length)) { bitmapImage = new BitmapImage(); bitmapImage.SetSource(stream); } return bitmapImage; } 例 private void TestImageConversion(object sender,RoutedEventArgs e) { byte[] image1AsByteArray = Image_Utility.ImageToByteArray((BitmapSource)Image1.Source); IsolatedStorage_Utility.Save<byte[]>("Image1.jpg",image1AsByteArray); BitmapSource image1AsBitmapImage = Image_Utility.ByteArrayToImage(IsolatedStorage_Utility.Load<byte[]>("Image1.jpg")); Image2.Source = image1AsBitmapImage; } 记住这是一个jpg保存.如果要保存png,您需要使用CodePlex库或创建自己的PNGEncoder. 我希望这有帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在64位Windows上将字符串从C返回到C#时,如何防止AccessViol
- 如何在Windows上从ffmpeg到python同时获取实时视频帧和时间
- windows – 终端服务 – 阻止用户在远程会话中使用本地打印
- active-directory – 如何配置非管理员帐户以使用Active Di
- microsoft-metro – 从自定义shell运行metro应用程序
- 在Windows上设置Git Bash中提示的颜色
- Windows Phone 7 – 通过Proxy使用RestSharp进行Web请求
- 屏蔽控制台应用程序的窗口#pragma comment(linker, "/s
- 单点登录 – ADFS被动请求=“没有注册协议处理程序”
- ILBC 规范
- windows-server-2008 – Windows Server 2008群集
- Windows关闭/重新启动通知程序提供延迟选项,类似
- 如何将两个windows vc静态库合并为一个
- 实现插件框架的最佳方式 – DLL是唯一的方法(C/C
- localhost,127.0.0.1 和 本机IP 三者的区别
- windows – 如何正确使用无模式窗体出现在任务栏
- Windows Filtering Platform用户模式或内核模式?
- Windows下安装jenkins,关闭jenkins,修改jenkin
- windows – 在Win32应用程序中模仿丙烯酸
- Windows – 如何获取Exchange 2007中所有分发列表