我在使用他们提供的诺基亚成像 SDK 示例之一中使用的一些示例代码时遇到问题。本质上,我正在尝试将图像保存到独立存储。我正在重用的代码已在解决方案的其他地方成功使用,但是当我尝试使用它时没有错误,但它不会继续执行以下语句。本质上,在该StorePhoto
方法中,一旦IBuffer buffer = await App.PhotoModel.RenderFullBufferAsync();
调用就不会发生错误,但不会运行低于实际执行保存到隔离存储操作的代码,因此不会保存图像。
SavePage.xaml.cs
private static string _photoModelPath = @"\Lockscreen\v1\PhotoModel";
private static string _photoModelBufferFilename = @"buffer.data";
public async static void StorePhoto()
{
string _photoModelPath = @"\Lockscreen\v1\LockScreen";
string _photoModelBufferFilename = @"buffer.data";
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.DirectoryExists(_photoModelPath))
{
storage.CreateDirectory(_photoModelPath);
}
if (storage.FileExists(_photoModelPath + @"\" + _photoModelBufferFilename))
{
storage.DeleteFile(_photoModelPath + @"\" + _photoModelBufferFilename);
}
IBuffer buffer = await App.PhotoModel.RenderFullBufferAsync(); //code exiting method with no error
if (buffer != null)
{
IsolatedStorageFileStream originalFile = storage.CreateFile(_photoModelPath + @"\" + _photoModelBufferFilename);
Stream bufferStream = buffer.AsStream();
bufferStream.CopyTo(originalFile);
bufferStream.Flush();
bufferStream.Close();
bufferStream.Dispose();
originalFile.Flush();
originalFile.Close();
originalFile.Dispose();
}
}
}
MainPage.xaml.cs
private async void _saveItem_Click(object sender, EventArgs e)
{
Helpers.SaveHelper.StorePhoto(); //calling the StorePhoto method here
}
PhotoModel.cs(来自诺基亚成像 SDK 示例)
/// <summary>
/// Renders current image with applied filters to a buffer and returns it.
/// Meant to be used where the filtered image is for example going to be
/// saved to a file.
/// </summary>
/// <returns>Buffer containing the filtered image data</returns>
public async Task<IBuffer> RenderFullBufferAsync()
{
using (BufferImageSource source = new BufferImageSource(_buffer))
using (FilterEffect effect = new FilterEffect(source) { Filters = _components })
using (JpegRenderer renderer = new JpegRenderer(effect))
{
return await renderer.RenderAsync();
}
}