我正在嘗試保存包含從相機返回到本地存儲文件夾的jpeg圖像的流。文件正在創建,但不幸的是根本沒有數據。下面是我嘗試使用代碼:將包含圖像的流保存到Windows Phone上的本地文件夾8
public async Task SaveToLocalFolderAsync(Stream file, string fileName)
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream fileStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0))
{
using (DataWriter dataWriter = new DataWriter(outputStream))
{
dataWriter.WriteBytes(UsefulOperations.StreamToBytes(file));
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
await outputStream.FlushAsync();
}
}
}
public static class UsefulOperations
{
public static byte[] StreamToBytes(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
}
的任何文件保存這樣的幫助,將不勝感激 - 所有幫助我發現網上參考保存文本。我正在使用Windows.Storage命名空間,因此它也可以在Windows 8上運行。
您確定這是Windows PHONE 8嗎?你沒有使用'IsolatedStorageFile.GetUserStoreForApplication()' –
絕對可以,你現在可以使用上面的命名空間,代碼也可以在Windows 8上運行。 –
每天學點新東西:) –