2014-01-31 45 views
1

我遇到了一些示例代碼問題,我正在使用它們提供的諾基亞圖像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(來自諾基亞成像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(); 
     } 
    } 

回答

0

原來來解決這個我必須將保存圖像的代碼放到我原先調用該方法的同一頁面中,並且它也必須是o f類型任務,以便異步/等待將正常工作。

+1

該代碼應該在項目的其他地方工作,把它放在助手/實用程序類中不應該是一個問題。問題在於你沒有等待_saveItem_Click對StorePhoto()的調用。所以使它成爲一個異步的任務方法是要走的路,然後等待電話。 –