在这个暴露第二种情况的代码中我遇到了一个问题“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上常见本地存储中的文件,或者如果你可以通过medialibrary给我解决问题,我会很高兴。
感谢
答案 0 :(得分:0)
使用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");
}
}