Ejemplo n.º 1
0
        async private Task InvertPhoto()
        {
            ProgressScreen loadingScreen = new ProgressScreen(0, transformedBitmap.Height);

            cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;

            Enabled = false;

            await Task.Run(() =>
            {
                for (int y = 0; y < transformedBitmap.Height && !token.IsCancellationRequested && !loadingScreen.CurrentState(); y++)
                {
                    for (int x = 0; x < transformedBitmap.Width; x++)
                    {
                        Color color  = transformedBitmap.GetPixel(x, y);
                        int newRed   = Math.Abs(color.R - 255);
                        int newGreen = Math.Abs(color.G - 255);
                        int newBlue  = Math.Abs(color.B - 255);

                        if (token.IsCancellationRequested)
                        {
                            this.cancel = true;
                            break;
                        }
                        if (loadingScreen.CurrentState())
                        {
                            this.cancel = true;
                            break;
                        }

                        Color newColor = Color.FromArgb(newRed, newGreen, newBlue);
                        transformedBitmap.SetPixel(x, y, newColor);
                    }
                    Invoke((Action) delegate() { loadingScreen.UpdateProgressBar(1); });
                }
                if (loadingScreen.CurrentState())
                {
                    this.cancel = true;
                }
                Invoke((Action) delegate() { loadingScreen.Close(); });
            });

            Enabled = true;
            Activate();
        }
Ejemplo n.º 2
0
        async private Task ColorChanger(float red, float green, float blue)
        {
            ProgressScreen loadingScreen = new ProgressScreen(0, transformedBitmap.Height);

            cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;
            await Task.Run(() =>
            {
                for (int y = 0; y < transformedBitmap.Height && !token.IsCancellationRequested && !loadingScreen.CurrentState(); y++)
                {
                    for (int x = 0; x < transformedBitmap.Width; x++)
                    {
                        Color color  = transformedBitmap.GetPixel(x, y);
                        int newRed   = Math.Abs(color.R - 255);
                        int newGreen = Math.Abs(color.G - 255);
                        int newBlue  = Math.Abs(color.B - 255);
                        float total  = (newRed + newGreen + newBlue) / 3;
                        total       /= 255;
                        if (token.IsCancellationRequested)
                        {
                            this.cancel = true;
                            break;
                        }
                        if (loadingScreen.CurrentState())
                        {
                            this.cancel = true;
                            break;
                        }
                        Color newColor = Color.FromArgb((int)(red *total), (int)(green *total), (int)(total *blue));
                        transformedBitmap.SetPixel(x, y, newColor);
                    }
                }
                if (loadingScreen.CurrentState())
                {
                    this.cancel = true;
                }
                Invoke((Action) delegate() { loadingScreen.Close(); });
            });
        }
Ejemplo n.º 3
0
        async private Task Slider()
        {
            ProgressScreen loadingScreen = new ProgressScreen(0, transformedBitmap.Height);

            cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;

            Enabled = false;

            await Task.Run(() =>
            {
                int amount = 0;
                Invoke((Action) delegate() { amount = Convert.ToInt32(2 * (50 - trackBar1.Value) * 0.01 * 255); });
                for (int y = 0; y < transformedBitmap.Height && !token.IsCancellationRequested && !loadingScreen.CurrentState(); y++)
                {
                    for (int x = 0; x < transformedBitmap.Width; x++)
                    {
                        Color color  = transformedBitmap.GetPixel(x, y);
                        int newRed   = color.R - amount;
                        int newGreen = color.G - amount;
                        int newBlue  = color.B - amount;

                        if (token.IsCancellationRequested)
                        {
                            this.cancel = true;
                            break;
                        }
                        if (loadingScreen.CurrentState())
                        {
                            this.cancel = true;
                            break;
                        }


                        if (newRed < 0)
                        {
                            newRed = 0;
                        }
                        else if (newRed > 255)
                        {
                            newRed = 255;
                        }

                        if (newGreen < 0)
                        {
                            newGreen = 0;
                        }
                        else if (newGreen > 255)
                        {
                            newGreen = 255;
                        }

                        if (newBlue < 0)
                        {
                            newBlue = 0;
                        }
                        else if (newBlue > 255)
                        {
                            newBlue = 255;
                        }


                        Color newColor = Color.FromArgb(newRed, newGreen, newBlue);
                        transformedBitmap.SetPixel(x, y, newColor);
                    }

                    Invoke((Action) delegate() { loadingScreen.UpdateProgressBar(1); });
                }
                if (loadingScreen.CurrentState())
                {
                    this.cancel = true;
                }
                Invoke((Action) delegate() { loadingScreen.Close(); });
            });

            Enabled = true;
            Activate();
        }