コード例 #1
0
        private Int32Rect calcolaRettangolo(Crop cropCorrezione, int imgWidth, int imgHeight)
        {
            // Rettangolo di crop
            Int32Rect croppingRect = new Int32Rect();

            croppingRect.X      = cropCorrezione.x;
            croppingRect.Y      = cropCorrezione.y;
            croppingRect.Width  = cropCorrezione.w;
            croppingRect.Height = cropCorrezione.h;

            // Immagine sorgente piccola
            Int32Size rectImgSorg = new Int32Size();

            rectImgSorg.Width  = cropCorrezione.imgWidth;
            rectImgSorg.Height = cropCorrezione.imgHeight;

            // Immagine di destinazione grande
            Int32Size rectImgDest = new Int32Size();

            rectImgDest.Width  = imgWidth;
            rectImgDest.Height = imgHeight;

            return(Geometrie.proporziona(croppingRect, rectImgSorg, rectImgDest));
        }
コード例 #2
0
ファイル: Grafik.cs プロジェクト: Semigroup/SageSystem
 private Geometrie Transform(Geometrie geo)
 {
     return (geo - LinksOben).ScaleLocal(ppm);
 }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: digiPHOTO-it/lumen
        private Canvas trasformaCanvasDefinitivo()
        {
            BitmapSource bmpSource = (BitmapSource)imgMaschera.Source;

            Int32 newWidth  = (int)((double)bmpSource.PixelWidth * 96d / bmpSource.DpiX);
            Int32 newHeight = (int)((double)bmpSource.PixelHeight * 96d / bmpSource.DpiY);

            Canvas c = new Canvas();

            c.Background = new SolidColorBrush(Colors.Transparent);

            foreach (Visual visual in MyCanvas.Children)
            {
                Image fotina = (Image)visual;
                Image fotona = new Image();
                fotona.Source = fotina.Source.Clone();                  // Clono l'immagine iniziale della foto

                Rect rectFotina   = new Rect(Canvas.GetLeft(fotina), Canvas.GetTop(fotina), fotina.ActualWidth, fotina.ActualHeight);
                Size sizeFondo    = new Size(imgMaschera.ActualWidth, imgMaschera.ActualHeight);
                Size sizeMaschera = new Size(newWidth, newHeight);

                Rect newRect = Geometrie.proporziona(rectFotina, sizeFondo, sizeMaschera);

                fotona.Width  = newRect.Width;
                fotona.Height = newRect.Height;
                c.Children.Add(fotona);

                // Imposto la posizione della foto all'interno del canvas della cornice.
                Canvas.SetLeft(fotona, newRect.Left);
                Canvas.SetTop(fotona, newRect.Top);


                // ----------------------------------------------
                // ---   ora mi occupo delle trasformazioni   ---
                // ----------------------------------------------

                if (fotina.RenderTransform is TransformGroup)
                {
                    TransformGroup newTg = new TransformGroup();

                    TransformGroup tg = (TransformGroup)fotina.RenderTransform;
                    foreach (Transform tx in tg.Children)
                    {
                        Debug.WriteLine("Trasformazione = " + tx.ToString());

                        if (tx is RotateTransform)
                        {
                            RotateTransform rtx = (RotateTransform)tx;
                            // L'angolo rimane uguale che tanto è in gradi
                            RotateTransform newTx = rtx.Clone();
                            // ricalcolo solo il punto centrale
                            newTx.CenterX = rtx.CenterX * fotona.Width / fotina.ActualWidth;
                            newTx.CenterY = rtx.CenterY * fotona.Height / fotina.ActualHeight;
                            newTg.Children.Add(newTx);
                        }
                        else if (tx is TranslateTransform)
                        {
                            TranslateTransform ttx = (TranslateTransform)tx;
                            // Devo riproporzionare le misure.
                            //  x1 : w1 = ? : w2
                            //  ? = x1 * w2 / w1
                            double             newX  = ttx.X * fotona.Width / fotina.ActualWidth;
                            double             newY  = ttx.Y * fotona.Height / fotina.ActualHeight;
                            TranslateTransform newTx = new TranslateTransform(newX, newY);
                            newTg.Children.Add(newTx);
                        }
                        else if (tx is MatrixTransform)
                        {
                            // Questo è il Flip
                            MatrixTransform mtx   = (MatrixTransform)tx;
                            MatrixTransform newTx = (MatrixTransform)tx.Clone();

                            Matrix mMatrix = new Matrix();
                            mMatrix.Scale(-1.0, 1.0);
                            mMatrix.OffsetX = mtx.Value.OffsetX * fotona.Width / fotina.ActualWidth;
                            newTx.Matrix    = mMatrix;

                            newTg.Children.Add(newTx);
                        }
                        else if (tx is ScaleTransform)
                        {
                            ScaleTransform stx = (ScaleTransform)tx;

                            // La scala rimane uguale perché è un fattore moltiplicativo.
                            ScaleTransform newTx = stx.Clone();
                            // ricalcolo solo il punto centrale
                            newTx.CenterX = stx.CenterX * fotona.Width / fotina.ActualWidth;
                            newTx.CenterY = stx.CenterY * fotona.Height / fotina.ActualHeight;
                            newTg.Children.Add(newTx);
                        }
                    }

                    fotona.RenderTransform = newTg;
                }
            }

            // per concludere, aggiungo anche la maschera che deve ricoprire tutto.
            Image maschera = new Image();

            maschera.Source = imgMaschera.Source.Clone();
            maschera.Width  = c.Width;
            maschera.Height = c.Height;

            c.Children.Add(maschera);

            // Non so se serve, ma dovrebbe provocare un ricalcolo delle posizioni dei componenti all'interno del canvas.
            c.InvalidateMeasure();
            c.InvalidateArrange();

            return(c);
        }