コード例 #1
0
        //put the bitmap as input image and set it for next steps
        private void SetInputImage(Bitmap inputBitmap)
        {
            var hBitmap = inputBitmap.GetHbitmap();
            var imgIn   = ((System.Windows.Controls.Image) this.FindName("InputImage"));

            if (imgIn.Source != null)
            {
                imgIn.Source = null;
            }

            try
            {
                var imageSource = Imaging.CreateBitmapSourceFromHBitmap(
                    hBitmap,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(inputBitmap.Width, inputBitmap.Height));

                imageSource.Freeze();
                imgIn.Source = imageSource;
            }
            finally
            {
                DeleteObject(hBitmap);

                imgIn.Width  = inputBitmap.Width;
                imgIn.Height = inputBitmap.Height;

                var inputInfoLabel = ((System.Windows.Controls.Label) this.FindName("InputInfoLabel"));
                inputInfoLabel.Content = $"x:{inputBitmap.Width} y:{inputBitmap.Height}";
                inputImage             = FilterImageConvert.FilterImageFromBitmap(inputBitmap);
            }
        }
コード例 #2
0
        private async Task ExecuteCurrentFilterTiled()
        {
            int tileSizeY;
            int tileSizeX;

            if (!int.TryParse(((TextBox)this.FindName("tileYbox")).Text, out tileSizeY) || !int.TryParse(((TextBox)this.FindName("tileXbox")).Text, out tileSizeX))
            {
                MessageBox.Show("invalid tile dimensions");
                return;
            }
            if (tileSizeX == 0 || tileSizeX > this.inputImage.Width || tileSizeY == 0 || tileSizeY > this.inputImage.Height)
            {
                MessageBox.Show("Tiles should be at least 1 pixel (x & y) and not bigger than the input image");
                return;
            }

            converting = true;
            //maybe display its settings again to see the up to date settings
            DisplayCurrentFilterSettings();

            PushProgress("Creating target Image", 1);
            //just run the converter with the first tile, to see how big the output tiles are
            Task <FilterImage> testConvertTask       = Task.Run(() => this.currentFilter.Execute(this.inputImage.GrabSubImage(0, 0, tileSizeX, tileSizeY)));
            FilterImage        testOutputFilterImage = await testConvertTask;

            int         scaleX      = testOutputFilterImage.Width / tileSizeX;
            int         scaleY      = testOutputFilterImage.Height / tileSizeY;
            FilterImage outputImage = new FilterImage(this.inputImage.Width * scaleX, this.inputImage.Height * scaleY);

            int offsetX;
            int offsetY        = 0;
            int tilesProcessed = 1;
            int tilesToProcess = (inputImage.Height / tileSizeY) * (inputImage.Width / tileSizeX);

            while (offsetY <= inputImage.Height - tileSizeY)
            {
                offsetX = 0;
                while (offsetX <= inputImage.Width - tileSizeX)
                {
                    PushProgress($"converting tile: {tilesProcessed} / {tilesToProcess}", 2);
                    Task <FilterImage> convertTileTask = Task.Run(() => this.currentFilter.Execute(this.inputImage.GrabSubImage(offsetX, offsetY, tileSizeX, tileSizeY)));
                    FilterImage        iOutputTile     = await convertTileTask;
                    outputImage.PutImage(offsetX * scaleX, offsetY * scaleY, iOutputTile);
                    offsetX += tileSizeX;
                    tilesProcessed++;
                }
                offsetY += tileSizeY;
            }

            //convert the result back to bitmap
            PushProgress("Fetching result", 3);
            var outputTask   = Task.Run(() => FilterImageConvert.BitmapFromFilterImage(outputImage));
            var outputBitmap = await outputTask;

            //apply the output bitmap guiwise
            PushProgress("Rendering result", 3);
            SetOutputImage(outputBitmap);

            converting = false;
        }
コード例 #3
0
        //perform the current selected filter with its current selected settings and input image
        private async Task ExecuteCurrentFilter()
        {
            if (null == inputImage)
            {
                //no image? dont do it silencly (no annoying message plz)
                return;
            }

            if (converting)
            {
                //only once
                return;
            }

            if ((((System.Windows.Controls.CheckBox) this.FindName("tileToggle")).IsChecked ?? false))
            {
                await ExecuteCurrentFilterTiled();

                return;
            }

            converting = true;
            //maybe display its settings again to see the up to date settings
            DisplayCurrentFilterSettings();

            PushProgress("Executing the filter", 1);
            //convert bitmap to filterImage and perform the filter
            var convertTask       = Task.Run(() => this.currentFilter.Execute(this.inputImage));
            var outputFilterImage = await convertTask;

            //convert the result back to bitmap
            PushProgress("Fetching result", 2);
            var outputTask   = Task.Run(() => FilterImageConvert.BitmapFromFilterImage(outputFilterImage));
            var outputBitmap = await outputTask;

            //apply the output bitmap guiwise
            PushProgress("Rendering result", 3);
            SetOutputImage(outputBitmap);

            converting = false;
        }