我真的混淆了Windows 8上的一些存储功能,我试图在本地手机存储中保存由几个应用程序共享的凭据(密码/用户)。从此,用户只需在一个应用程序中更改一次密码,所有应用程序都会更改密码。我经历了三种可能性
在这段公开第二种情况的代码中,我遇到了一个问题"System.InvalidOperationException.An意外错误发生了“。
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上的公共本地存储中,或者您能给我一个解决这个问题的方法,我会很高兴的。
谢谢
发布于 2014-01-06 14:37:33
使用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");
}
}https://stackoverflow.com/questions/20950741
复制相似问题