使用wp7将多个图像保存到隔离存储中

时间:2011-06-20 05:37:27

标签: windows-phone-7 isolatedstorage

我的代码能够将1个图像保存到windows phone 7中的独立存储中,但如何更改它以便能够将1个以上的图像保存到隔离的存储中。现在,每当我想要保存新图像最新的图像将与旧图像重叠,所以任何人都可以帮我改变我的代码或使用的样本。谢谢很多

我的代码:

 private void saveButtonClick(object sender, RoutedEventArgs e)
    {
        try
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isf.FileExists("myImage.jpg"))
                    isf.DeleteFile("myImage.jpg");

                using (IsolatedStorageFileStream isfs = isf.CreateFile("myImage.jpg"))
                {
                    var bmp = new WriteableBitmap(myImageElement, myImageElement.RenderTransform);
                    bmp.SaveJpeg(isfs, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
                }
            }
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message);
        }
    }

1 个答案:

答案 0 :(得分:1)

当你给每个文件命名相同时,你的文件会被覆盖 如果你想要多个文件,他们需要有唯一的名字。通过删除代码中的硬编码名称并为每个文件使用适当/唯一的名称来执行此操作。