Search code examples
windows-phone-8sdkcropnokiaimaging

Crop an Image in nokia Imaging SDK 1.2?


Can you give me a sample code for crop an Image using Nokia Imaging SDK 1.2 ? As you know the "Editing Session" class, that I use for cropping Image has gone in SDK 1.2. Thanks for your attention.


Solution

  • This is an excerpt from the nokia api reference documentation which can be found here:

    http://developer.nokia.com/resources/library/Imaging_API_Ref/nokiagraphicsimaging-namespace/cropfilter-class.html

    This sample takes CameraCaptureTask result photo and applies a [crop] filter to it.

    async void CaptureTask_Completed(object sender, PhotoResult e)
    {
        // Create a source to read the image from PhotoResult stream
        using (var source = new StreamImageSource(e.ChosenPhoto))
        {
            // Create effect collection with the source stream
            using (var filters = new FilterEffect(source))
            {
                // Initialize the filter 
                var sampleFilter = new CropFilter(new Windows.Foundation.Rect(0, 0, 500, 500));
    
                // Add the filter to the FilterEffect collection
                filters.Filters = new IFilter[] { sampleFilter };
    
                // Create a target where the filtered image will be rendered to
                var target = new WriteableBitmap((int)ImageControl.ActualWidth, (int)ImageControl.ActualHeight);
    
                // Create a new renderer which outputs WriteableBitmaps
                using (var renderer = new WriteableBitmapRenderer(filters, target))
                {
                    // Render the image with the filter(s)
                    await renderer.RenderAsync();
    
                    // Set the output image to Image control as a source
                    ImageControl.Source = target;
                }
            }
        }
    }