0

我一直在写一篇关于 windowsphone 的文章。我创建了一个地址变量,包括一个 uri 以将图像添加到地址中。使用隔离存储保存数据时出现错误。我不知道为什么。请帮我!太感谢了。

class Address
{
   private string name;
   private Uri icon;
   .....
}

……

public void save()
    {
        XmlWriterSettings xmlwritersetting = new XmlWriterSettings();
        xmlwritersetting.Indent = true;
            using (IsolatedStorageFile myisolatedstiragefile = IsolatedStorageFile.GetUserStoreForApplication())
        {

            if (myisolatedstiragefile.FileExists(filename))
            {
                myisolatedstiragefile.DeleteFile(filename);
            }

            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, System.IO.FileMode.OpenOrCreate, myisolatedstiragefile))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Adress>));
                using (XmlWriter writer = XmlWriter.Create(stream, xmlwritersetting))
                {
                    serializer.Serialize(writer, listadress);
                }
            }
        }
    }
4

1 回答 1

0

我有点难以理解你的问题,但我会努力的。您确实应该指出您在调试器中具体遇到的错误以及它发生的位置。

但只是通过查看,您似乎正在尝试使用 XmlSerializer 将二进制图像数据写入 iso-storage,这可能行不通。您可以找到许多将 iso-storage 用于各种目的的示例,包括在此处编写图像文件:http: //www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Images

例如,它表明您可以通过执行以下操作将 JPG 图像保存到独立存储中:

    // Create a filename for JPEG file in isolated storage.
            String tempJPEG = "logo.jpg";             
    // Create virtual store and file stream. Check for duplicate tempJPEG files. 
           using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())            {
                if (myIsolatedStorage.FileExists(tempJPEG))                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
            }  
               IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG); 
                StreamResourceInfo sri = null;
                Uri uri = new Uri(tempJPEG, UriKind.Relative);
                sri = Application.GetResourceStream(uri);
                 BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);
                 // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                 //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);                fileStream.Close();
            } 
于 2012-11-20T20:56:29.787 回答