【问题标题】:Saving multiple images into isolated storage with wp7使用 wp7 将多个图像保存到隔离存储中
【发布时间】:2011-06-20 05:37:27
【问题描述】:

我的代码能够将 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);
        }
    }

【问题讨论】:

    标签: windows-phone-7 isolatedstorage


    【解决方案1】:

    您的文件正在被覆盖,因为您为每个文件指定了相同的名称。
    如果您想要多个文件,则它们需要具有唯一的名称。通过删除代码中的硬编码名称并为每个文件使用适当/唯一的名称来做到这一点。

    【讨论】:

    • 是的...但是如何生成自动名称?不介意帮我改一下代码,让我看看。谢谢
    • 名称需要与应用中图像的使用方式相关。有很多方法可以使名称独一无二。
    猜你喜欢
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多