コード例 #1
0
        public static async Task <WriteableBitmap> AdjustCurvesEffect(WriteableBitmap imgSource)
        {
            //var imgSource = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
            //bitmap.CopyToBuffer(imgSource.PixelBuffer);

            var source = new BitmapImageSource(imgSource.AsBitmap());

            var curvesEffect = new CurvesEffect
            {
                Source = source
            };

            //allow for curve values to be set via settings pane with
            var globalCurve = new Curve(CurveInterpolation.NaturalCubicSpline, new[]
            {
                new Point(200, 62)
            });

            //156, 78
            //new Point(110, 34)

            curvesEffect.Red   = globalCurve;
            curvesEffect.Green = globalCurve;
            curvesEffect.Blue  = globalCurve;

            var adjustedImg = new WriteableBitmap(imgSource.PixelWidth, imgSource.PixelHeight);

            using (var renderer = new WriteableBitmapRenderer(curvesEffect, adjustedImg))
            {
                // Generate the gray image
                await renderer.RenderAsync();
            }

            return(adjustedImg);
        }
コード例 #2
0
        public async static Task <WriteableBitmap> Render(WriteableBitmap actualImage, List <IFilter> filters)
        {
            var bitmap = actualImage.AsBitmap();
            BitmapImageSource bitmapSource = new BitmapImageSource(bitmap);

            FilterEffect effects = new FilterEffect(bitmapSource);

            effects.Filters = filters;
            WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(effects, actualImage);

            return(await renderer.RenderAsync());
        }
コード例 #3
0
        private static IReadOnlyList <IImageProvider> CreateFramedAnimation(IReadOnlyList <IImageProvider> images, Rect animationBounds, int w, int h)
        {
            List <IImageProvider> framedAnimation = new List <IImageProvider>();

            WriteableBitmap maskBitmap = new WriteableBitmap(w, h);

            var backgroundRectangle = new Rectangle
            {
                Fill   = new SolidColorBrush(Colors.Black),
                Width  = w,
                Height = h,
            };

            maskBitmap.Render(backgroundRectangle, new TranslateTransform());

            var foregroundRectangle = new Rectangle
            {
                Fill   = new SolidColorBrush(Colors.White),
                Width  = animationBounds.Width,
                Height = animationBounds.Height,
            };

            TranslateTransform foregroundTranslate = new TranslateTransform
            {
                X = animationBounds.X,
                Y = animationBounds.Y
            };

            maskBitmap.Render(foregroundRectangle, foregroundTranslate);
            maskBitmap.Invalidate();

            foreach (IImageProvider frame in images)
            {
                FilterEffect filterEffect = new FilterEffect(images[0]);

                BlendFilter blendFilter = new BlendFilter(frame, BlendFunction.Normal, 1.0)
                {
                    MaskSource = new BitmapImageSource(maskBitmap.AsBitmap())
                };

                filterEffect.Filters = new List <IFilter>()
                {
                    blendFilter
                };
                framedAnimation.Add(filterEffect);
            }

            return(framedAnimation);
        }
コード例 #4
0
        public static async Task <WriteableBitmap> ApplyStampThreshold(WriteableBitmap imgSource, double threshold)
        {
            var source = new BitmapImageSource(imgSource.AsBitmap());
            var effect = new Lumia.Imaging.Artistic.StampEffect(source, 0, threshold);

            var stampImage = new WriteableBitmap(imgSource.PixelWidth, imgSource.PixelHeight);

            using (var renderer = new WriteableBitmapRenderer(effect, stampImage))
            {
                // Generate the gray image
                await renderer.RenderAsync();
            }

            return(stampImage);
        }
コード例 #5
0
        public static async Task <WriteableBitmap> ApplyGaussianBlur(WriteableBitmap imgSource, int kernelS)
        {
            BitmapImageSource source = new BitmapImageSource(imgSource.AsBitmap());
            BlurEffect        effect = new BlurEffect(source, kernelS);

            WriteableBitmap blurredImage = new WriteableBitmap(imgSource.PixelWidth, imgSource.PixelHeight);

            using (var renderer = new WriteableBitmapRenderer(effect, blurredImage))
            {
                // Generate the gray image
                await renderer.RenderAsync();
            }

            return(blurredImage);
        }
コード例 #6
0
        private async Task ApplyFilter(ImageFilter imageFilter, Image image)
        {
            FilterEffect effect = new FilterEffect(new BitmapImageSource(ImageToFilter.AsBitmap()));

            effect.Filters = new IFilter[] { imageFilter.Filter };

            WriteableBitmap         temporaryImage = new WriteableBitmap(MainPage.ImageToFilter);
            WriteableBitmapRenderer renderer       = new WriteableBitmapRenderer(effect, temporaryImage);
            await renderer.RenderAsync();

            image.Source = temporaryImage;
            // Here we create a new EditingSession based on our selected image and add the selected filter to it
            // After the picture gets rendered to our delivered image
            //editingSession = new EditingSession(ImageToFilter.AsBitmap());
            //editingSession.AddFilter(imageFilter.Filter);
            //await editingSession.RenderToImageAsync(image, OutputOption.PreserveAspectRatio);
        }
コード例 #7
0
        async Task processRenderingLR()
        {
            var time = DateTime.Now;

            session.UndoAll();


            var currentSize = new Size(
                outputSize.Width / currentScale,
                outputSize.Height / currentScale);
            var corner = new Point(currentPos.X - currentSize.Width / 2, currentPos.Y - currentSize.Height / 2);


            session.AddFilter(CreateOrientedROIFilter(new Rect(corner, currentSize), currentAngle));

            await session.RenderToBitmapAsync(outputBitmapLRTmp.AsBitmap());

            outputBitmapLRTmp.Pixels.CopyTo(outputBitmapLR.Pixels, 0);
            outputBitmapLR.Invalidate();
            if (output.Source != outputBitmapLR)
            {
                output.Source = outputBitmapLR;
            }

            lastDuration = DateTime.Now - time;
            if (nbLRImage == 0)
            {
                minLRtime = lastDuration;
                maxLRtime = lastDuration;
            }
            if (lastDuration < minLRtime)
            {
                minLRtime = lastDuration;
            }
            if (lastDuration > maxLRtime)
            {
                maxLRtime = lastDuration;
            }

            sumLRtime += lastDuration;
            nbLRImage++;
        }
コード例 #8
0
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel panel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                int i = 0;

                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;

                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
                    {
                        App.PhotoModel.ApplyFilter(filter);
                        App.PhotoModel.Dirty = true;

                        NavigationService.GoBack();
                    };

                    panel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel FiltersWrapPanel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                //render filtered photo
                int i = 0;
                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    //crop the bitmap
                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;
                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += async delegate
                    {
                        ProgressIndicator.IsRunning = true;
                        SetScreenButtonsEnabled(false);

                        App.ThumbnailModel.UndoAllFilters();
                        App.ThumbnailModel.ApplyFilter(filter, _shouldCrop);
                        App.ThumbnailModel.Dirty = true;

                        WriteableBitmap photo = new WriteableBitmap((int)App.ThumbnailModel.Width, (int)App.ThumbnailModel.Height);
                        await App.ThumbnailModel.RenderBitmapAsync(photo);

                        PhotoViewer.Source = photo;

                        SetScreenButtonsEnabled(true);
                        ProgressIndicator.IsRunning = false;
                    };

                    FiltersWrapPanel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
            ProgressIndicator.IsRunning = false;
        }
コード例 #10
0
ファイル: SegmenterPage.xaml.cs プロジェクト: guido1993/blurp
        private async void AttemptUpdatePreviewAsync()
        {
            if (!Processing)
            {
                Processing = true;

                do
                {
                    _processingPending = false;

                    if (Model.OriginalImage != null && ForegroundAnnotationsDrawn && BackgroundAnnotationsDrawn)
                    {
                        Model.OriginalImage.Position = 0;

                        var maskBitmap        = new WriteableBitmap((int)AnnotationsCanvas.ActualWidth, (int)AnnotationsCanvas.ActualHeight);
                        var annotationsBitmap = new WriteableBitmap((int)AnnotationsCanvas.ActualWidth, (int)AnnotationsCanvas.ActualHeight);

                        annotationsBitmap.Render(AnnotationsCanvas, new ScaleTransform
                        {
                            ScaleX = 1,
                            ScaleY = 1
                        });

                        annotationsBitmap.Invalidate();

                        Model.OriginalImage.Position = 0;

                        using (var source = new StreamImageSource(Model.OriginalImage))
                            using (var segmenter = new InteractiveForegroundSegmenter(source))
                                using (var renderer = new WriteableBitmapRenderer(segmenter, maskBitmap))
                                    using (var annotationsSource = new BitmapImageSource(annotationsBitmap.AsBitmap()))
                                    {
                                        var foregroundColor = Model.ForegroundBrush.Color;
                                        var backgroundColor = Model.BackgroundBrush.Color;

                                        segmenter.ForegroundColor   = Windows.UI.Color.FromArgb(foregroundColor.A, foregroundColor.R, foregroundColor.G, foregroundColor.B);
                                        segmenter.BackgroundColor   = Windows.UI.Color.FromArgb(backgroundColor.A, backgroundColor.R, backgroundColor.G, backgroundColor.B);
                                        segmenter.Quality           = 0.5;
                                        segmenter.AnnotationsSource = annotationsSource;

                                        await renderer.RenderAsync();

                                        MaskImage.Source = maskBitmap;

                                        maskBitmap.Invalidate();

                                        Model.AnnotationsBitmap = (Bitmap)annotationsBitmap.AsBitmap();
                                    }
                    }
                    else
                    {
                        MaskImage.Source = null;
                    }
                }while (_processingPending && !_manipulating);

                Processing = false;
            }
            else
            {
                _processingPending = true;
            }
        }
コード例 #11
0
ファイル: PhotoModel.cs プロジェクト: JorgeCupiV/MusicLens
 /// <summary>
 /// Renders current image with applied filters to the given bitmap.
 /// </summary>
 /// <param name="bitmap">Bitmap to render to</param>
 public async Task RenderBitmapAsync(WriteableBitmap bitmap)
 {
     await _session.RenderToBitmapAsync(bitmap.AsBitmap());
 }
コード例 #12
0
        ///////////////////////////////////////////////////////////////////////////
        // Use the Nokia Imaging SDK to apply a filter to a selected image

        private async void AppBarBtnEdit_Click(object sender, RoutedEventArgs e)
        {
            progressRing.IsEnabled  = true;
            progressRing.IsActive   = true;
            progressRing.Visibility = Visibility.Visible;

            // Create NOK Imaging SDK effects pipeline and run it
            var imageStream = new BitmapImageSource(originalBitmap.AsBitmap());

            using (var effect = new FilterEffect(imageStream))
            {
                var filter = new Lumia.Imaging.Adjustments.GrayscaleFilter();
                effect.Filters = new[] { filter };

                // Render the image to a WriteableBitmap.
                var renderer = new WriteableBitmapRenderer(effect, originalBitmap);
                editedBitmap = await renderer.RenderAsync();

                editedBitmap.Invalidate();
            }

            Image.Source = originalBitmap;

            Image.Visibility = Visibility.Collapsed;



            //Resizing the editedBitmap to 128x128
            var resized1 = editedBitmap.Resize(128, 128, Windows.UI.Xaml.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

            //converting the editedBitmap to byte array
            byte[] edit_arr = resized1.ToByteArray();



            //obtaining the images folder
            StorageFolder folder    = Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFolder subfolder = await folder.GetFolderAsync("Images");


            //create list of all the files in the images folder
            var pictures = await subfolder.GetFilesAsync();



            double ldiff    = 50;          //least percentage difference for an image to be a match
            string dispText = "Try again"; //default message to be displayed

            byte threshold = 124;

            //process through all images
            foreach (var file in pictures)
            {
                if (file != null)
                {
                    // Use WriteableBitmapEx to easily load image from a stream
                    using (var stream = await file.OpenReadAsync())
                    {
                        listBitmap = await new WriteableBitmap(1, 1).FromStream(stream);
                        stream.Dispose();
                    }

                    //convert obtained image to byte array
                    byte[] list_arr = listBitmap.ToByteArray();


                    byte[] difference = new byte[edit_arr.Length];

                    //compare byte array of both the images
                    for (int i = 0; i < list_arr.Length; i++)
                    {
                        difference[i] = (byte)Math.Abs(edit_arr[i] - list_arr[i]);
                    }


                    //calculate percentage difference
                    int differentPixels = 0;

                    foreach (byte b in difference)
                    {
                        if (b > threshold)
                        {
                            differentPixels++;
                        }
                    }

                    double percentage = (double)differentPixels / (double)list_arr.Length;
                    percentage = percentage * 100;


                    if (percentage <= ldiff)
                    {
                        ldiff    = percentage;
                        dispText = file.DisplayName;
                    }
                }
            }

            tb.Text = dispText;

            progressRing.IsEnabled  = false;
            progressRing.IsActive   = false;
            progressRing.Visibility = Visibility.Collapsed;


            tb.Visibility    = Visibility.Visible;
            Image.Visibility = Visibility.Visible;


            var tmp = new RenderTargetBitmap();
            await tmp.RenderAsync(source);

            var buffer = await tmp.GetPixelsAsync();

            var width  = tmp.PixelWidth;
            var height = tmp.PixelHeight;

            editedBitmap = await new WriteableBitmap(1, 1).FromPixelBuffer(buffer, width, height);

            AppBarBtnSpeech.IsEnabled  = true;
            AppBarBtnSpeech.Visibility = Visibility.Visible;

            AppBarBtnSave.IsEnabled = true;
        }