Exemplo n.º 1
0
        private void transformationSettingsChanged(object sender, EventArgs e)
        {
            needRedraw = true;

            if (BackgroundTransformator.Instance.PerspectiveRatio == perspectiveRatio &&
                BackgroundTransformator.Instance.PerspectiveFarSide == perspectivefarSide)
            {
                return;
            }

            perspectiveRatio   = -1 * BackgroundTransformator.Instance.PerspectiveRatio;
            perspectivefarSide = BackgroundTransformator.Instance.PerspectiveFarSide;

            if (perspectiveRatio == 0)
            {
                shot = new Bitmap(shotUnwarped);
                return;
            }

            int farHeightDiff = (int)(shotUnwarped.Height * perspectiveRatio / 2);
            int farDistance   = Math.Min(shotUnwarped.Width - 1, (int)(shotUnwarped.Width * perspectivefarSide));

            Point topleft = new Point(perspectiveRatio >= 0 ? 0 : shotUnwarped.Width - farDistance,
                                      perspectiveRatio > 0 ? 0 : -farHeightDiff);
            Point topright = new Point(perspectiveRatio >= 0 ? farDistance : shotUnwarped.Width,
                                       perspectiveRatio > 0 ? farHeightDiff : 0);
            Point bottomleft = new Point(perspectiveRatio >= 0 ? 0 : shotUnwarped.Width - farDistance,
                                         perspectiveRatio > 0
                                             ? shotUnwarped.Height
                                             : shotUnwarped.Height + farHeightDiff);
            Point bottomright = new Point(perspectiveRatio >= 0 ? farDistance : shotUnwarped.Width,
                                          perspectiveRatio > 0
                                              ? shotUnwarped.Height - farHeightDiff
                                              : shotUnwarped.Height);
            Bitmap tmp = new Bitmap(shotUnwarped);
            int    gen = ++transformationGeneration;
            Thread t   = new Thread(new ThreadStart(delegate {
                Bitmap distorted = QuadDistort.Distort(
                    tmp, topleft, topright, bottomleft, bottomright);

                if (gen != transformationGeneration)
                {
                    return;
                }

                ((Control)editor).Invoke(new MethodInvoker(
                                             delegate {
                    Graphics graphics = Graphics.FromImage(shot);
                    graphics.Clear(Color.Transparent);
                    graphics.DrawImageUnscaled(distorted, 0, 0);
                    distorted.Dispose();
                    tmp.Dispose();
                    needRedraw = true;
                    editor.invalidateView();
                }));
            }));

            t.Start();
        }
Exemplo n.º 2
0
        public void Edit(string sourcePath, string destinationPath)
        {
            //Skewing strategy
            //By using 4(X,Y) Points from user input it distorts the image with those coordinates
            //using the QuadDistort additional class
            //This class uses source(string), 4 Points(int X, int Y) and destinationPath(string) as user inputs

            try
            {
                Point topLeft     = new Point(x1, y1);
                Point topRight    = new Point(x2, y2);
                Point bottomLeft  = new Point(x3, y3);
                Point bottomRight = new Point(x4, y4);

                //Transofrming image to a Bitmap to use QuadDistort function
                Image  imgPhoto      = Image.FromFile(sourcePath);
                Bitmap transitionBmp = (Bitmap)imgPhoto;

                //Additional function that distorts image
                Bitmap bmp = QuadDistort.Distort(transitionBmp, topLeft, topRight, bottomLeft, bottomRight);
                bmp.Save(destinationPath);
            }

            catch (FileNotFoundException)
            {
                Console.WriteLine("The specified file could not be found!");
                Console.WriteLine();
            }
            catch (FileLoadException)
            {
                Console.WriteLine("File could not be loaded!");
                Console.WriteLine();
            }
            catch (FormatException)
            {
                Console.WriteLine("Sorry, that is not a valid format!");
            }
            catch (PathTooLongException)
            {
                Console.WriteLine("File name is too long!");
            }
            catch (Exception)
            {
                Console.WriteLine("Something went wrong...");
            }
        }