如何从Nokia Imaging SDK保存图像

时间:2014-01-31 02:47:12

标签: c# isolatedstorage nokia-imaging-sdk lumia-imaging-sdk

我在使用他们提供的诺基亚Imaging SDK样本中的一些示例代码时遇到问题。基本上我正在尝试将图像保存到IsolatedStorage。我正在重用的代码已在解决方案的其他地方成功使用,但是当我尝试使用它时没有错误,但它不会继续以下语句。基本上在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(来自Nokia Imaging 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();
        }
    }

1 个答案:

答案 0 :(得分:0)

原来要解决这个问题我必须将保存图像的代码放到我最初调用该方法的同一页面中,并且它还需要是Task类型,以便async / await能正常工作。 / p>