How get image from isolated storage

送分小仙女□ 提交于 2019-12-01 10:49:18

In your Single Class the Img property should be of type ImageSource. To set this property (read the image from IsolatedStorage) you can do this:

private ImageSource getImageFromIsolatedStorage(string imageName)
{
    BitmapImage bimg = new BitmapImage();

    using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = iso.OpenFile(imageName, FileMode.Open, FileAccess.Read))
        {
            bimg.SetSource(stream);
        }
    }
    return bimg;
}

Then in your code snippet:

using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
    IsolatedStorageFileStream isoStoreStream = isoStore.OpenFile("chart.xml", FileMode.Open);
    using (StreamReader reader = new StreamReader(isoStoreStream))
    {
        XElement xml = XElement.Parse(reader.ReadToEnd());
        var list = from var in xml.Descendants("Pos")
            select new Single
            {
                Pos = Int32.Parse(var.Attribute("id").Value),
                Img = getImageFromIsolatedStorage(string.Format("{0}.jpg", Pos));
            };

Here is a very complete example of how to write to and read from ISO storage.

http://www.codeproject.com/Articles/38636/Saving-Bitmaps-to-Isolated-Storage-in-Silverlight-.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!