コード例 #1
0
        private async Task ApplyImageFilter(bool parallel)
        {
            int stride = _image.PixelWidth * 4;

            lblError.Visibility = Visibility.Collapsed;

            //Do the processing on a background thread so the UI remains responsive
            var processingResults = await Task <PixelProcessingResults> .Run(() =>
            {
                PixelProcessingResults result;

                try {
                    byte[] pixelArray = new byte[_image.PixelHeight * _image.PixelWidth * 4];
                    _image.CopyPixels(pixelArray, stride, 0);

                    if (parallel == true)
                    {
                        pixelArray = ApplyAntiqueFilterParallel(pixelArray);
                    }
                    else
                    {
                        pixelArray = ApplyAntiqueFilter(pixelArray);
                    }

                    result = new PixelProcessingResults(true, pixelArray);
                }
                catch (Exception)
                {
                    result = new PixelProcessingResults(false);
                }

                return(result);
            });

            if (processingResults.Success)
            {
                _image = BitmapSource.Create(_image.PixelWidth, _image.PixelHeight, _image.DpiX, _image.DpiY,
                                             PixelFormats.Bgr32, null, processingResults.Pixels, stride);
                FullImage.Source = _image;
            }
            else
            {
                lblError.Visibility = Visibility.Visible;
            }
        }
コード例 #2
0
ファイル: ImagePage.xaml.cs プロジェクト: Ronacs/WinDevCamp
        private async Task ApplyImageFilter(bool parallel)
        {
            int stride = _image.PixelWidth * 4;

            lblError.Visibility = Visibility.Collapsed;

            //Do the processing on a background thread so the UI remains responsive
            var processingResults = await Task<PixelProcessingResults>.Run(() =>
            {
                PixelProcessingResults result;

                try {
                    byte[] pixelArray = new byte[_image.PixelHeight * _image.PixelWidth * 4];
                    _image.CopyPixels(pixelArray, stride, 0);

                    if (parallel == true)
                    {
                        pixelArray = ApplyAntiqueFilterParallel(pixelArray);
                    }
                    else
                    {
                        pixelArray = ApplyAntiqueFilter(pixelArray);
                    }

                    result = new PixelProcessingResults(true, pixelArray);
                }
                catch (Exception)
                {
                    result = new PixelProcessingResults(false);
                }

                return result;
            });

            if (processingResults.Success)
            {
                _image = BitmapSource.Create(_image.PixelWidth, _image.PixelHeight, _image.DpiX, _image.DpiY,
                        PixelFormats.Bgr32, null, processingResults.Pixels, stride);
                FullImage.Source = _image;
            }
            else
            {
                lblError.Visibility = Visibility.Visible;
            }

        }