How to Save an Image from Nokia Imaging SDK

483 Views Asked by At

I am having issues with some sample code that I am using from one of Nokia's Imaging SDK samples they provide. Essentially I am trying to save an image to IsolatedStorage. The code that I am reusing has been used successfully elsewhere in the solution, but when I try to use it there are no errors but it does not proceed with the following statements. Essentially in the StorePhoto method, once IBuffer buffer = await App.PhotoModel.RenderFullBufferAsync(); is called no error occurs but no code below that which is actually performs the save to isolated storage operation is ran, so no image is ever saved.

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 (from Nokia Imaging SDK sample)

/// <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

There are 1 best solutions below

1
On

Turns out to solve this I had to put the code that saves the image into the same page that I was originally calling that method, and also it needs to be of type Task so that the async/await will work properly.