none
How To Save Image Using Lumia Imaging SDK RRS feed

  • Question

  • Hi,

    I'm using Lumia Imaging SDK in UWP. I have successfully implemented file picking from picture gallery and applying different effects on it. Now i want to save the filtered image in picture gallery. 

    In Demo Project JPGRender is used to save the image.  e;g    

    using (var jpegRenderer = new JpegRenderer(_grayscaleEffect))

    but this example only save the grayscaleeffect only. I want to save the filtered image which is on the SwapChainPanel.

    How to Save the image which is filtered or rendered on SwapChainPanel..?

    Also how to use camera and and set captured image as a source for renderer.?

    I am using this code for filtering picked image

     using (var source = new StorageFileImageSource(file))
                    using (var HDR = new HdrEffect(source))
                    using (var renderer = new SwapChainPanelRenderer(HDR, SwapChainPanelTarget))
                    {
                        await renderer.RenderAsync();
                    }


    Osama Usmani

    Tuesday, August 23, 2016 6:28 PM

Answers

  • Hi Asama Usmani,

    Welcome to the Developing Universal Windows apps forum! 

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .

    >>How to Save the image which is filtered or rendered on SwapChainPanel..?

    The Lumia Imaging SDK already have a completed sample to save the rendered pictures which are on SwapChainPanel. You can download the sample EditShowCase for testing https://github.com/Microsoft/Lumia-imaging-sdk/tree/master/Samples/EditShowcase. And the save image method in the sample is as follows:

     public async Task<bool> SaveImageAsync(StorageFile file)
     {
         if (m_SelectedEffect == null)
         {
             return false;
         }
    
         string errorMessage = null;
    
         try
         {
             using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
             {
                 // Jpeg renderer gives the raw buffer containing the effected image.
                 var renderResult = await m_renderer.RenderAsync(m_SelectedEffect, RenderOption.RenderAtSourceSize | RenderOption.RenderToJpeg);
                 await stream.WriteAsync(renderResult.Buffer);
                 await stream.FlushAsync();
             }
         }
         catch (Exception exception)
         {
             errorMessage = exception.Message;
         }
    
         if (!string.IsNullOrEmpty(errorMessage))
         {
             var dialog = new MessageDialog(errorMessage);
             await dialog.ShowAsync();
             return false;
         }
    
         return true;
     }

    >>Also how to use camera and and set captured image as a source for renderer.?

    For this requirements, if you just want to simply capture a picture for using, you can use CameraCaptureUI class. Details please see: https://msdn.microsoft.com/en-us/windows/uwp/audio-video-camera/capture-photos-and-video-with-cameracaptureui

    You can capture the picture as a storage file and the next steps are same with your other picture file.

    CameraCaptureUI captureUI = new CameraCaptureUI();
    captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
    captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); 
    
    StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
    
    if (photo == null)
    {
        // User cancelled photo capture
        return;
    }



    Best Regards, Sunteen Wu




    • Edited by Sunteen Wu Wednesday, August 24, 2016 7:19 AM
    • Proposed as answer by Sunteen Wu Tuesday, August 30, 2016 8:06 AM
    • Marked as answer by Barry WangModerator Wednesday, August 31, 2016 7:17 AM
    Wednesday, August 24, 2016 7:16 AM