【问题标题】:Save bytearray (encrypted password) as Picture using medialibrary WP8使用 medialibrary WP8 将字节数组(加密密码)保存为图片
【发布时间】:2014-01-23 21:39:47
【问题描述】:

我真的对 Windows Phone 8 上的一些存储功能感到困惑。我试图将由多个应用程序共享的凭据(密码/用户)保存在本地手机存储中。 从那里,用户将只能在一个应用程序中更改密码一次,并且它将为所有应用程序更改。 我经历过3种可能

  1. 保存在外部服务器上
  2. 在 Medialibrary 上另存为图片
  3. 保存在用于管理凭据的新特定应用的独立存储中

在暴露第二种情况的这段代码中,我遇到了一个问题“System.InvalidOperationException。发生了意外错误”

    public static void SaveToFile(byte[] Encryptedfile, string FileName)
    {      
        using (var mediaLibrary = new MediaLibrary())
        {
            using (var stream = new MemoryStream(Encryptedfile))
            {
                    var file = string.Format(FileName, Guid.NewGuid());
                    stream.Seek(0, SeekOrigin.Begin);
                    var picture = mediaLibrary.SavePicture(file, stream);  //ERROR
            }
        }
    }

函数的调用

        byte[] PasswordByte = Encoding.UTF8.GetBytes(password);
        byte[] UserByte = Encoding.UTF8.GetBytes(user);

        byte[] EncryptedPasswordUser = ProtectedData.Protect(PasswordByte, null);
        byte[] EncryptedUser = ProtectedData.Protect(UserByte, null);


        IsolatedStorageOperations.SaveToFile(EncryptedPasswordUser, "Password");
        IsolatedStorageOperations.SaveToFile(EncryptedUser, "User");

如果你能给我另一种方法来将文件保存在 WP8 上的公共本地存储中,或者你能给我解决媒体库问题的方法,我会很高兴。

谢谢

【问题讨论】:

    标签: image windows-phone-8 bytearray encryption media-library


    【解决方案1】:

    使用 WriteableBitmap 将图像保存在媒体库中。希望对你有帮助

    public static void SaveToFile(byte[] Encryptedfile, string FileName)
         {
           using (var stream = new MemoryStream(Encryptedfile))
             {
             var file = string.Format(FileName, Guid.NewGuid());
             WriteableBitmap bitmap = new WriteableBitmap(100,100);
             bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
             stream.Seek(0, SeekOrigin.Begin);
             using (MediaLibrary mediaLibrary = new MediaLibrary())
              mediaLibrary.SavePicture(file , stream);
             MessageBox.Show("Image saved");
             }
         }
    

    【讨论】:

    • 我已经尝试过使用 writableimage 但我在 Savepicture 方法上遇到了同样的问题?我能以图片格式保存任何类型的字节数组吗?因为我提醒你密码和用户最初是在字节[]中转换的字符串...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2017-08-06
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多