Exemple #1
0
        void ISvgRenderer.RotateTransform(float fAngle, MatrixOrder order)
        {
            if (fAngle == 0)
            {
                return;
            }

            var rotation = Matrix3x2.CreateRotation((float)(fAngle * Math.PI / 180));

            _currentTransform        = order == MatrixOrder.Append ? Matrix3x2.Multiply(_currentTransform, rotation) : Matrix3x2.Multiply(rotation, _currentTransform);
            _innerGraphics.Transform = Matrix3x2.Multiply(_currentTransform, _initialTransform);
        }
Exemple #2
0
        void ISvgRenderer.ScaleTransform(float sx, float sy, MatrixOrder order)
        {
            if (sx == 1 && sy == 1)
            {
                return;
            }

            var scale = Matrix3x2.CreateScale(sx, sy);

            _currentTransform        = order == MatrixOrder.Append ? Matrix3x2.Multiply(_currentTransform, scale) : Matrix3x2.Multiply(scale, _currentTransform);
            _innerGraphics.Transform = Matrix3x2.Multiply(_currentTransform, _initialTransform);
        }
Exemple #3
0
 public void Scale(float sx, float sy)
 {
     dc.Transform = Matrix3x2.Multiply(Matrix3x2.Scaling(sx, sy), dc.Transform);
 }
Exemple #4
0
 public void Translate(float dx, float dy)
 {
     dc.Transform = Matrix3x2.Multiply(Matrix3x2.Translation(dx, dy), dc.Transform);
 }
        public static async Task <StorageFile> DrawStrokesAsync(StorageFile file, IReadOnlyList <SmoothPathBuilder> strokes, Rect rectangle, BitmapRotation rotation, BitmapFlip flip)
        {
            var device = CanvasDevice.GetSharedDevice();
            var bitmap = await CanvasBitmap.LoadAsync(device, file.Path);

            var canvas1 = new CanvasRenderTarget(device, (float)bitmap.Size.Width, (float)bitmap.Size.Height, bitmap.Dpi);
            var canvas2 = new CanvasRenderTarget(device, (float)bitmap.Size.Width, (float)bitmap.Size.Height, bitmap.Dpi);

            var size       = canvas1.Size.ToVector2();
            var canvasSize = canvas1.Size.ToVector2();

            var scaleX = 1 / (float)rectangle.Width;
            var scaleY = 1 / (float)rectangle.Height;

            var offsetX = (float)rectangle.X * scaleX;
            var offsetY = (float)rectangle.Y * scaleY;

            if (rotation == BitmapRotation.Clockwise270Degrees ||
                rotation == BitmapRotation.Clockwise90Degrees)
            {
                size = new Vector2(size.Y, size.X);

                scaleX = scaleY;
                scaleY = 1 * 1 / (float)rectangle.Width;
            }

            using (var session = canvas1.CreateDrawingSession())
            {
                switch (rotation)
                {
                case BitmapRotation.Clockwise90Degrees:
                    var transform1 = Matrix3x2.CreateRotation(MathFEx.ToRadians(90));
                    transform1.Translation = new Vector2(size.Y, 0);
                    session.Transform      = transform1;
                    break;

                case BitmapRotation.Clockwise180Degrees:
                    var transform2 = Matrix3x2.CreateRotation(MathFEx.ToRadians(180));
                    transform2.Translation = new Vector2(size.X, size.Y);
                    session.Transform      = transform2;
                    break;

                case BitmapRotation.Clockwise270Degrees:
                    var transform3 = Matrix3x2.CreateRotation(MathFEx.ToRadians(270));
                    transform3.Translation = new Vector2(0, size.X);
                    session.Transform      = transform3;
                    break;
                }

                switch (flip)
                {
                case BitmapFlip.Horizontal:
                    switch (rotation)
                    {
                    case BitmapRotation.Clockwise90Degrees:
                    case BitmapRotation.Clockwise270Degrees:
                        session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateScale(1, -1, canvasSize / 2));
                        break;

                    default:
                        session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateScale(-1, 1, canvasSize / 2));
                        break;
                    }
                    break;

                case BitmapFlip.Vertical:
                    switch (rotation)
                    {
                    case BitmapRotation.None:
                    case BitmapRotation.Clockwise180Degrees:
                        session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateScale(1, -1, canvasSize / 2));
                        break;

                    default:
                        session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateScale(-1, 1, canvasSize / 2));
                        break;
                    }
                    break;
                }

                session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateScale(scaleX, scaleY));
                session.Transform = Matrix3x2.Multiply(session.Transform, Matrix3x2.CreateTranslation(-(offsetX * size.X), -(offsetY * size.Y)));

                foreach (var builder in strokes)
                {
                    PencilCanvas.DrawPath(session, builder, size);
                }
            }

            using (var session = canvas2.CreateDrawingSession())
            {
                session.DrawImage(bitmap);
                session.DrawImage(canvas1);
            }

            bitmap.Dispose();

            using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                await canvas2.SaveAsync(stream, CanvasBitmapFileFormat.Jpeg /*, 0.77f*/);
            }

            canvas2.Dispose();
            canvas1.Dispose();

            return(file);
        }
Exemple #6
0
 public static Matrix3x2 Multiply(this Matrix3x2 value, Single multiplier)
 {
     return(Matrix3x2.Multiply(value, multiplier));
 }
Exemple #7
0
 public static Matrix3x2 Multiply(this Matrix3x2 first, Matrix3x2 second)
 {
     return(Matrix3x2.Multiply(first, second));
 }