Storing key-value pair settings in silverlight
I have a class in silverlight that I would like to store to disk. It contains a couple of basic CLR objects - strings and integers, and a WPF BitmapImage.
What is the best way to store this to a file? I have tried serializing the class and dumping it to file, but BitmapImage does not support serializing.
Ideally, I want to store the bitmapimage as a physical image on disk (.png .jpg etc), and store the CLR objects in some key-value pair settings file. This is so easy in WPF, since it natively supports KVP project settings, but in Silverlight th开发者_高级运维ere are many more restrictions.
Any advice is much appreciated!
In order to store KeyValuePairs without much fuss on the local machine, I'd consider using IsolatedStorageSettings.ApplicationSettings dictionary collection.
Here's an example of that: http://msdn.microsoft.com/en-us/library/cc221360(VS.95).aspx
If you'd like to store a BitmapImage to IsoStore, I'd suggest using a Image Encoder of sorts in conjunction with WriteableBitmap. Placing your BitmapImage (via an Image control) in a WriteableBitmap will give you access to each individual pixel. Using a PngEncoder you can save an actual image file for that image.
Jeff prosise has a sample of that here: http://www.wintellect.com/CS/blogs/jprosise/archive/2009/07/17/fun-with-savefiledialog-and-writeablebitmap.aspx
For the image part, if you can use WriteableBitmap
instead of BitmapImage
, then maybe this helps: http://www.codeproject.com/Articles/38636/Saving-Bitmaps-to-Isolated-Storage-in-Silverlight-.aspx?display=Print
精彩评论