Example #1
0
        public VideoManager(Image nPreviewImage, Image nProcessedimage)
        {
            this.previewImage     = nPreviewImage;
            this.processedImage   = nProcessedimage;
            previewImage.Source   = new SoftwareBitmapSource();
            processedImage.Source = new SoftwareBitmapSource();

            helper = new OpenCVBridge.OpenCVHelper();
        }
Example #2
0
        public void SetHolographicSpace(HolographicSpace holographicSpace)
        {
            this.holographicSpace = holographicSpace;

            //
            // TODO: Add code here to initialize your content.
            //

#if DRAW_SAMPLE_CONTENT
            // Initialize the sample hologram.
            spinningCubeRenderer = new SpinningCubeRenderer(deviceResources);

            spatialInputHandler = new SpatialInputHandler();
#endif

            // Use the default SpatialLocator to track the motion of the device.
            locator = SpatialLocator.GetDefault();

            // Be able to respond to changes in the positional tracking state.
            locator.LocatabilityChanged += this.OnLocatabilityChanged;

            // Respond to camera added events by creating any resources that are specific
            // to that camera, such as the back buffer render target view.
            // When we add an event handler for CameraAdded, the API layer will avoid putting
            // the new camera in new HolographicFrames until we complete the deferral we created
            // for that handler, or return from the handler without creating a deferral. This
            // allows the app to take more than one frame to finish creating resources and
            // loading assets for the new holographic camera.
            // This function should be registered before the app creates any HolographicFrames.
            holographicSpace.CameraAdded += this.OnCameraAdded;

            // Respond to camera removed events by releasing resources that were created for that
            // camera.
            // When the app receives a CameraRemoved event, it releases all references to the back
            // buffer right away. This includes render target views, Direct2D target bitmaps, and so on.
            // The app must also ensure that the back buffer is not attached as a render target, as
            // shown in DeviceResources.ReleaseResourcesForBackBuffer.
            holographicSpace.CameraRemoved += this.OnCameraRemoved;

            // The simplest way to render world-locked holograms is to create a stationary reference frame
            // when the app is launched. This is roughly analogous to creating a "world" coordinate system
            // with the origin placed at the device's position as the app is launched.
            referenceFrame = locator.CreateStationaryFrameOfReferenceAtCurrentLocation();

            // Notes on spatial tracking APIs:
            // * Stationary reference frames are designed to provide a best-fit position relative to the
            //   overall space. Individual positions within that reference frame are allowed to drift slightly
            //   as the device learns more about the environment.
            // * When precise placement of individual holograms is required, a SpatialAnchor should be used to
            //   anchor the individual hologram to a position in the real world - for example, a point the user
            //   indicates to be of special interest. Anchor positions do not drift, but can be corrected; the
            //   anchor will use the corrected position starting in the next frame after the correction has
            //   occurred.
            fingerTracker = new FingerTracking(referenceFrame, holographicSpace);

            test = new OpenCVBridge.OpenCVHelper();
        }
Example #3
0
        private async void OpenCVButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // <SnippetOpenCVBlur>
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;

            var inputFile = await fileOpenPicker.PickSingleFileAsync();

            if (inputFile == null)
            {
                // The user cancelled the picking operation
                return;
            }

            SoftwareBitmap inputBitmap;

            using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file
                inputBitmap = await decoder.GetSoftwareBitmapAsync();
            }

            if (inputBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                inputBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)
            {
                inputBitmap = SoftwareBitmap.Convert(inputBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            }

            SoftwareBitmap outputBitmap = new SoftwareBitmap(inputBitmap.BitmapPixelFormat, inputBitmap.PixelWidth, inputBitmap.PixelHeight, BitmapAlphaMode.Premultiplied);


            var helper = new OpenCVBridge.OpenCVHelper();

            helper.Blur(inputBitmap, outputBitmap);

            var bitmapSource = new SoftwareBitmapSource();
            await bitmapSource.SetBitmapAsync(outputBitmap);

            imageControl.Source = bitmapSource;
            // </SnippetOpenCVBlur>
        }
        private void OpenCV_Click(object sender, RoutedEventArgs e)
        {
            openCVHelper = new OpenCVBridge.OpenCVHelper();

            InitOpenCVFrameReader();
        }
Example #5
0
        private async void Options_changed(object sender, SelectionChangedEventArgs e)
        {
            if (Cut.IsSelected)
            {
                string        desiredName       = DateTime.Now.Ticks + ".jpg";
                StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                RenderTargetBitmap bitmap = new RenderTargetBitmap();
                await bitmap.RenderAsync(Img);

                var pixelBuffer = await bitmap.GetPixelsAsync();

                using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                         BitmapAlphaMode.Ignore,
                                         (uint)bitmap.PixelWidth,
                                         (uint)bitmap.PixelHeight,
                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                         pixelBuffer.ToArray());
                    await encoder.FlushAsync();
                }



                if (saveFile != null)
                {
                    CutPicture(saveFile);
                }
            }
            else
            {
                if (addfilter.IsSelected)
                {
                    string        desiredName       = DateTime.Now.Ticks + ".jpg";
                    StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                    StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                    StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                    RenderTargetBitmap bitmap = new RenderTargetBitmap();
                    await bitmap.RenderAsync(Img);

                    var pixelBuffer = await bitmap.GetPixelsAsync();

                    using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                        encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                             BitmapAlphaMode.Ignore,
                                             (uint)bitmap.PixelWidth,
                                             (uint)bitmap.PixelHeight,
                                             DisplayInformation.GetForCurrentView().LogicalDpi,
                                             DisplayInformation.GetForCurrentView().LogicalDpi,
                                             pixelBuffer.ToArray());
                        await encoder.FlushAsync();
                    }
                    if (saveFile != null)
                    {
                        BlankPage2 editor = new BlankPage2();
                        editor.Show(saveFile);

                        editor.ImageEditedCompleted += (image_edited) =>
                        {
                            Img.Source = image_edited;
                        };
                    }
                }
                else
                {
                    if (blur.IsSelected)
                    {
                        string        desiredName       = DateTime.Now.Ticks + ".jpg";
                        StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                        StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                        StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                        RenderTargetBitmap bitmap = new RenderTargetBitmap();
                        await bitmap.RenderAsync(Img);

                        var pixelBuffer = await bitmap.GetPixelsAsync();

                        using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                            encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                                 BitmapAlphaMode.Ignore,
                                                 (uint)bitmap.PixelWidth,
                                                 (uint)bitmap.PixelHeight,
                                                 DisplayInformation.GetForCurrentView().LogicalDpi,
                                                 DisplayInformation.GetForCurrentView().LogicalDpi,
                                                 pixelBuffer.ToArray());
                            await encoder.FlushAsync();
                        }


                        if (saveFile == null)
                        {
                            // The user cancelled the picking operation
                            return;
                        }


                        SoftwareBitmap inputBitmap;
                        using (IRandomAccessStream stream = await saveFile.OpenAsync(FileAccessMode.Read))
                        {
                            // Create the decoder from the stream
                            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                            // Get the SoftwareBitmap representation of the file
                            inputBitmap = await decoder.GetSoftwareBitmapAsync();
                        }

                        if (inputBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                            inputBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)
                        {
                            inputBitmap = SoftwareBitmap.Convert(inputBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                        }

                        SoftwareBitmap outputBitmap = new SoftwareBitmap(inputBitmap.BitmapPixelFormat, inputBitmap.PixelWidth, inputBitmap.PixelHeight, BitmapAlphaMode.Premultiplied);


                        var helper = new OpenCVBridge.OpenCVHelper();
                        helper.Blur(inputBitmap, outputBitmap);

                        var bitmapSource = new SoftwareBitmapSource();
                        await bitmapSource.SetBitmapAsync(outputBitmap);

                        Img.Source = bitmapSource;
                    }
                    else
                    {
                        if (scrawl.IsSelected)
                        {
                            string        desiredName       = DateTime.Now.Ticks + ".jpg";
                            StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                            StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                            StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                            RenderTargetBitmap bitmap = new RenderTargetBitmap();
                            await bitmap.RenderAsync(Img);

                            var pixelBuffer = await bitmap.GetPixelsAsync();

                            using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                            {
                                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                                encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                                     BitmapAlphaMode.Ignore,
                                                     (uint)bitmap.PixelWidth,
                                                     (uint)bitmap.PixelHeight,
                                                     DisplayInformation.GetForCurrentView().LogicalDpi,
                                                     DisplayInformation.GetForCurrentView().LogicalDpi,
                                                     pixelBuffer.ToArray());
                                await encoder.FlushAsync();
                            }

                            if (saveFile != null)
                            {
                                scrawl editor = new scrawl();
                                editor.Show(saveFile);

                                editor.ImageEditedCompleted += (image_edited) =>
                                {
                                    Img.Source = image_edited;
                                };
                            }
                        }
                        else
                        {
                            if (open.IsSelected)
                            {
                                //文件选择器
                                FileOpenPicker openPicker = new FileOpenPicker();
                                //初始位置
                                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                                //添加文件类型
                                openPicker.FileTypeFilter.Add(".jpg");
                                openPicker.FileTypeFilter.Add(".jpeg");
                                openPicker.FileTypeFilter.Add(".png");
                                openPicker.FileTypeFilter.Add(".gif");
                                //选取单个文件
                                Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();



                                if (file != null)
                                {
                                    using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
                                    {
                                        var srcImage = new BitmapImage();
                                        await srcImage.SetSourceAsync(stream);

                                        Img.Source = srcImage;
                                    }
                                }
                            }
                            else
                            {
                                if (regenerate.IsSelected)
                                {
                                    MyFrame.Navigate(typeof(Page1));
                                }
                                else
                                {
                                    if (Camera.IsSelected)
                                    {
                                        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;
                                        }

                                        IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);

                                        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                                        SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                                        SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
                                                                                                   BitmapPixelFormat.Bgra8,
                                                                                                   BitmapAlphaMode.Premultiplied);

                                        SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
                                        await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

                                        Img.Source = bitmapSource;
                                    }
                                    else
                                    {
                                        if (save.IsSelected)
                                        {
                                            FileSavePicker savefile = new FileSavePicker();
                                            //初始位置
                                            savefile.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                                            // 显示在下拉列表的文件类型
                                            savefile.FileTypeChoices.Add("图片", new List <string>()
                                            {
                                                ".png", ".jpg", ".jpeg", ".bmp"
                                            });
                                            // 默认的文件名
                                            savefile.SuggestedFileName = "SaveFile";

                                            StorageFile sFile = await savefile.PickSaveFileAsync();

                                            if (sFile != null)
                                            {
                                                // 在用户完成更改并调用CompleteUpdatesAsync之前,阻止对文件的更新
                                                CachedFileManager.DeferUpdates(sFile);
                                                //把控件变成图像
                                                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                                                //传入参数Image控件
                                                await renderTargetBitmap.RenderAsync(Img);

                                                IBuffer pixelbuffer = await renderTargetBitmap.GetPixelsAsync();

                                                using (var fileStream = await sFile.OpenAsync(FileAccessMode.ReadWrite))
                                                {
                                                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                                                    encoder.SetPixelData(
                                                        BitmapPixelFormat.Bgra8,
                                                        BitmapAlphaMode.Ignore,
                                                        (uint)renderTargetBitmap.PixelWidth,
                                                        (uint)renderTargetBitmap.PixelHeight,
                                                        DisplayInformation.GetForCurrentView().LogicalDpi,
                                                        DisplayInformation.GetForCurrentView().LogicalDpi,
                                                        pixelbuffer.ToArray()
                                                        );
                                                    //刷新图像
                                                    await encoder.FlushAsync();
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (Sharpen.IsSelected)
                                            {
                                                string        desiredName       = DateTime.Now.Ticks + ".jpg";
                                                StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                                                StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                                                StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                                                RenderTargetBitmap bitmap = new RenderTargetBitmap();
                                                await bitmap.RenderAsync(Img);

                                                var pixelBuffer = await bitmap.GetPixelsAsync();

                                                using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                                                {
                                                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                                                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                                                         BitmapAlphaMode.Ignore,
                                                                         (uint)bitmap.PixelWidth,
                                                                         (uint)bitmap.PixelHeight,
                                                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                                                         pixelBuffer.ToArray());
                                                    await encoder.FlushAsync();
                                                }

                                                if (saveFile != null)
                                                {
                                                    BlankPage1 editor = new BlankPage1();
                                                    editor.Show(saveFile);

                                                    editor.ImageEditedCompleted += (image_edited) =>
                                                    {
                                                        Img.Source = image_edited;
                                                    };
                                                }
                                            }
                                            else
                                            {
                                                string        desiredName       = DateTime.Now.Ticks + ".jpg";
                                                StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
                                                StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

                                                StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

                                                RenderTargetBitmap bitmap = new RenderTargetBitmap();
                                                await bitmap.RenderAsync(Img);

                                                var pixelBuffer = await bitmap.GetPixelsAsync();

                                                using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                                                {
                                                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                                                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                                                         BitmapAlphaMode.Ignore,
                                                                         (uint)bitmap.PixelWidth,
                                                                         (uint)bitmap.PixelHeight,
                                                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                                                         DisplayInformation.GetForCurrentView().LogicalDpi,
                                                                         pixelBuffer.ToArray());
                                                    await encoder.FlushAsync();
                                                }



                                                if (saveFile != null)
                                                {
                                                    paster editor = new paster();
                                                    editor.Show(saveFile);

                                                    editor.ImageEditedCompleted += (image_edited) =>
                                                    {
                                                        Img.Source = image_edited;
                                                    };
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        private async void mohu_Click(object sender, RoutedEventArgs e)
        {
            string        desiredName       = DateTime.Now.Ticks + ".jpg";
            StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
            StorageFolder folder            = await applicationFolder.CreateFolderAsync("Pic", CreationCollisionOption.OpenIfExists);

            StorageFile saveFile = await folder.CreateFileAsync(desiredName, CreationCollisionOption.OpenIfExists);

            RenderTargetBitmap bitmap = new RenderTargetBitmap();
            await bitmap.RenderAsync(Img);

            var pixelBuffer = await bitmap.GetPixelsAsync();

            using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                     BitmapAlphaMode.Ignore,
                                     (uint)bitmap.PixelWidth,
                                     (uint)bitmap.PixelHeight,
                                     DisplayInformation.GetForCurrentView().LogicalDpi,
                                     DisplayInformation.GetForCurrentView().LogicalDpi,
                                     pixelBuffer.ToArray());
                await encoder.FlushAsync();
            }


            if (saveFile == null)
            {
                // The user cancelled the picking operation
                return;
            }


            SoftwareBitmap inputBitmap;

            using (IRandomAccessStream stream = await saveFile.OpenAsync(FileAccessMode.Read))
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file
                inputBitmap = await decoder.GetSoftwareBitmapAsync();
            }

            if (inputBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                inputBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)
            {
                inputBitmap = SoftwareBitmap.Convert(inputBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            }

            SoftwareBitmap outputBitmap = new SoftwareBitmap(inputBitmap.BitmapPixelFormat, inputBitmap.PixelWidth, inputBitmap.PixelHeight, BitmapAlphaMode.Premultiplied);


            var helper = new OpenCVBridge.OpenCVHelper();

            helper.Blur(inputBitmap, outputBitmap);

            var bitmapSource = new SoftwareBitmapSource();
            await bitmapSource.SetBitmapAsync(outputBitmap);

            Img.Source = bitmapSource;
        }
Example #7
0
        private async Task ApplyEffect()
        {
            ShowProgressBar("FlyoutLoading");
            var id           = OpenedEffect.getId();
            var helper       = new OpenCVBridge.OpenCVHelper();
            var bitmapSource = new SoftwareBitmapSource();

            OutputBitmap = new SoftwareBitmap(SelectedBitmap.BitmapPixelFormat, SelectedBitmap.PixelWidth, SelectedBitmap.PixelHeight, BitmapAlphaMode.Premultiplied);

            // BUG saves black image to storage in some implementations //
            if (id == Effect.BRIGHTNESS)
            {
                double brightness = GetDoubleValueFromTextBox(EffectBrightnessAmountBox) / 100;

                await Task.Run(() => helper.Brightness(SelectedBitmap, OutputBitmap, brightness));
            }
            else if (id == Effect.CONVOLUTION)
            {
                await Task.Run(() => helper.Convolution(SelectedBitmap, OutputBitmap, LastConvolution));
            }
            else if (id == Effect.FLIP)
            {
                await Task.Run(() => helper.Flip(SelectedBitmap, OutputBitmap));
            }
            else if (id == Effect.GRAY)
            {
                await Task.Run(() => helper.Gray(SelectedBitmap, OutputBitmap));
            }
            else if (id == Effect.RANDOM_LINES)
            {
                int horizontalSpace = GetIntValueFromTextBox(EffectRandomLinesHorizontalSpaceBox);
                int verticalSpace   = GetIntValueFromTextBox(EffectRandomLinesVerticalSpaceBox);

                await Task.Run(() => helper.RandomLines(SelectedBitmap, OutputBitmap, horizontalSpace, verticalSpace));
            }
            else if (id == Effect.RGB)
            {
                double r = GetDoubleValueFromTextBox(EffectRGB_RBox, 100) / 100;
                double g = GetDoubleValueFromTextBox(EffectRGB_GBox, 100) / 100;
                double b = GetDoubleValueFromTextBox(EffectRGB_BBox, 100) / 100;

                await Task.Run(() => helper.RGBComponents(SelectedBitmap, OutputBitmap, r, g, b));
            }
            else if (id == Effect.ROTATE)
            {
                double angle = GetIntValueFromTextBox(EffectRotateAngleBox, 90) * Math.PI / 180;

                await Task.Run(() => helper.Rotate(SelectedBitmap, OutputBitmap, angle));
            }
            else if (id == Effect.SEPIA)
            {
                await Task.Run(() => helper.Sepia(SelectedBitmap, OutputBitmap));
            }
            else if (id == Effect.PIXELATED)
            {
                int radius = GetIntValueFromTextBox(EffectPixelateRadiusBox);

                await Task.Run(() => helper.Pixelate(SelectedBitmap, OutputBitmap, radius));
            }
            else if (id == Effect.PLOT)
            {
                int    precision = GetIntValueFromTextBox(EffectPlotPrecisionBox);
                double scaleX    = GetDoubleValueFromTextBox(EffectPlotScaleXBox, 1);
                double scaleY    = GetDoubleValueFromTextBox(EffectPlotScaleYBox, 1);

                await Task.Run(() => helper.Plot(SelectedBitmap, OutputBitmap, LastPlotFunction, precision, scaleX, scaleY));
            }
            await bitmapSource.SetBitmapAsync(OutputBitmap);

            ResultImage.Source    = bitmapSource;
            ResetButton.IsEnabled = true;
            HideProgressBar();
        }
Example #8
0
        // 选取图片
        private async Task PickFile()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            }; //新建文件选取器

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg"); //联合图像专家组(JPEG)
            picker.FileTypeFilter.Add(".png");  //便携式网络图形(PNG)
            picker.FileTypeFilter.Add(".gif");  //图形交换格式(GIF)
            picker.FileTypeFilter.Add(".tiff"); //标记图像文件格式(TIFF)
            picker.FileTypeFilter.Add(".bmp");  //位图(BMP)
            picker.FileTypeFilter.Add(".ico");  //图标(ICO)



            // Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                // IRandomAccessStream stream = await file.OpenReadAsync();
                // <BitmapImage有关文档:https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.bitmapimage>
                // BitmapImage bitmap = new BitmapImage(); //新建Bitmap图像
                // await bitmap.SetSourceAsync(stream);
                // originImage.Source = bitmap;
                // Application now has read/write access to the picked file

                SoftwareBitmap inputBitmap;
                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    // Create the decoder from the stream
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                    // Get the SoftwareBitmap representation of the file
                    inputBitmap = await decoder.GetSoftwareBitmapAsync();
                }
                if (inputBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                    inputBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)
                {
                    inputBitmap = SoftwareBitmap.Convert(inputBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }
                SoftwareBitmap outputBitmap = new SoftwareBitmap(inputBitmap.BitmapPixelFormat, inputBitmap.PixelWidth, inputBitmap.PixelHeight, BitmapAlphaMode.Premultiplied);

                var helper = new OpenCVBridge.OpenCVHelper();
                helper.Blur(inputBitmap, outputBitmap);

                var bitmapSource = new SoftwareBitmapSource();
                await bitmapSource.SetBitmapAsync(outputBitmap);

                originImage.Source = bitmapSource;

                this.textBlock.Text = "Picked photo: " + file.Name;
            }
            else
            {
                this.textBlock.Text = "Operation cancelled.";
            }
        }