public void RotateTransform_InvalidOrder ()
 {
     using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp))
     {
         pgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
     }
 }
        public void RotateTransform()
        {
            using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) {
                pgb.RotateTransform(90);
                float[] elements = pgb.Transform.Elements;
                Assert.AreEqual(0, elements[0], 0.1, "matrix.0");
                Assert.AreEqual(1, elements[1], 0.1, "matrix.1");
                Assert.AreEqual(-1, elements[2], 0.1, "matrix.2");
                Assert.AreEqual(0, elements[3], 0.1, "matrix.3");
                Assert.AreEqual(0, elements[4], 0.1, "matrix.4");
                Assert.AreEqual(0, elements[5], 0.1, "matrix.5");

                pgb.RotateTransform(270);
                Assert.IsTrue(pgb.Transform.IsIdentity, "Transform.IsIdentity");
            }
        }
예제 #3
0
 private PathGradientBrush GetSpecialCapBrush(GaugeGraphics g, GraphicsPath path, PointF pointOrigin, float angle, Color fillColor, GradientType fillGradientType, Color fillGradientEndColor, GaugeHatchStyle fillHatchStyle)
 {
     using (GraphicsPath graphicsPath = (GraphicsPath)path.Clone())
     {
         graphicsPath.Flatten(null, 0.3f);
         graphicsPath.Reset();
         RectangleF bounds = path.GetBounds();
         bounds.Inflate(-20f, -20f);
         PointF[] points = new PointF[4]
         {
             new PointF(bounds.Left, bounds.Top),
             new PointF(bounds.Right, bounds.Top),
             new PointF(bounds.Right, bounds.Bottom),
             new PointF(bounds.Left, bounds.Bottom)
         };
         graphicsPath.AddLines(points);
         PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
         pathGradientBrush.SurroundColors = new Color[4]
         {
             Color.Red,
             Color.Green,
             Color.Blue,
             Color.Green
         };
         pathGradientBrush.CenterColor = Color.Transparent;
         pathGradientBrush.CenterPoint = new PointF(bounds.Left, bounds.Top);
         pathGradientBrush.RotateTransform(angle, MatrixOrder.Append);
         pathGradientBrush.TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append);
         return(pathGradientBrush);
     }
 }
예제 #4
0
파일: form1.cs 프로젝트: zhimaqiao51/docs
        // </snippet1>



        // Snippet for: M:System.Drawing.Drawing2D.PathGradientBrush.RotateTransform(System.Single,System.Drawing.Drawing2D.MatrixOrder)
        // <snippet2>
        public void RotateTransformExample(PaintEventArgs e)
        {
            // Create a graphics path and add an ellipse.
            GraphicsPath myPath = new GraphicsPath();
            Rectangle    rect   = new Rectangle(100, 20, 100, 50);

            myPath.AddRectangle(rect);

            // Get the path's array of points.
            PointF[] myPathPointArray = myPath.PathPoints;

            // Create a path gradient brush.
            PathGradientBrush myPGBrush = new
                                          PathGradientBrush(myPathPointArray);

            // Set the color span.
            myPGBrush.CenterColor = Color.Red;
            Color[] mySurroundColor = { Color.Blue };
            myPGBrush.SurroundColors = mySurroundColor;

            // Draw the brush to the screen prior to transformation.
            e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);

            // Apply the rotate transform to the brush.
            myPGBrush.RotateTransform(45, MatrixOrder.Append);

            // Draw the brush to the screen again after applying the
            // transform.
            e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
        }
 public void RotateTransform_InvalidOrder()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) {
             pgb.RotateTransform(720, (MatrixOrder)Int32.MinValue);
         }
     });
 }
예제 #6
0
 public MyGradientBrush(Color color, string imagePath = "picture.jpg") : base(color, imagePath)
 {
     Point[] points = { new Point(20, 20), new Point(40, 140), new Point(100, 40) };
     brush = new PathGradientBrush(points, WrapMode.TileFlipXY);
     brush.SurroundColors = new Color[] { color, Color.Red, Color.Cyan };
     brush.CenterColor    = Color.White;
     brush.CenterPoint    = new PointF(50, 40);
     brush.RotateTransform(30);
 }
    public void Transform_Operations ()
    {
        using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp))
        {
            Matrix clone = pgb.Transform.Clone ();
            Matrix mul = clone.Clone ();

            clone.Multiply (mul, MatrixOrder.Append);
            pgb.MultiplyTransform (mul, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");

            clone.Multiply (mul, MatrixOrder.Prepend);
            pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");

            clone.Rotate (45, MatrixOrder.Append);
            pgb.RotateTransform (45, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");

            clone.Rotate (45, MatrixOrder.Prepend);
            pgb.RotateTransform (45, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");

            clone.Scale (0.25f, 2, MatrixOrder.Append);
            pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Scale/Append");

            clone.Scale (0.25f, 2, MatrixOrder.Prepend);
            pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");

            clone.Translate (10, 20, MatrixOrder.Append);
            pgb.TranslateTransform (10, 20, MatrixOrder.Append);
            Assert.AreEqual (pgb.Transform, clone, "Translate/Append");

            clone.Translate (30, 40, MatrixOrder.Prepend);
            pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
            Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");

            clone.Reset ();
            pgb.ResetTransform ();
            Assert.AreEqual (pgb.Transform, clone, "Reset");
        }
    }
 public void RotateTransform_Min()
 {
     using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.Clamp)) {
         pgb.RotateTransform(Single.MinValue);
         float[] elements = pgb.Transform.Elements;
         Assert.AreEqual(-5.93904E+36, elements[0], 1e32, "matrix.0");
         Assert.AreEqual(-5.93904E+36, elements[1], 1e32, "matrix.1");
         Assert.AreEqual(5.93904E+36, elements[2], 1e32, "matrix.2");
         Assert.AreEqual(-5.93904E+36, elements[3], 1e32, "matrix.3");
         Assert.AreEqual(0, elements[4], 0.1, "matrix.4");
         Assert.AreEqual(0, elements[5], 0.1, "matrix.5");
     }
 }
예제 #9
0
 private static void DrawShadow(Graphics graphics, GraphicsPath graphicsPath,
                                Color shadowColor)
 {
     using (PathGradientBrush brush = new PathGradientBrush(graphicsPath))
     {
         ColorBlend colorBlend = new ColorBlend(3);
         colorBlend.Colors = new[] { Color.Transparent,
                                     shadowColor,
                                     Color.Transparent };
         colorBlend.Positions      = new[] { 0f, .06f, 1f };
         brush.InterpolationColors = colorBlend;
         brush.RotateTransform(-0.15f);
         graphics.FillPath(brush, graphicsPath);
     }
 }
        public void Rectangle()
        {
            using (PathGradientBrush pgb = new PathGradientBrush(pts_2f, WrapMode.TileFlipXY)) {
                CheckDefaultRectangle("Original", pgb.Rectangle);
                pgb.MultiplyTransform(new Matrix(2, 0, 0, 2, 2, 2));
                CheckDefaultRectangle("Multiply", pgb.Rectangle);
                pgb.ResetTransform();
                CheckDefaultRectangle("Reset", pgb.Rectangle);
                pgb.RotateTransform(90);
                CheckDefaultRectangle("Rotate", pgb.Rectangle);
                pgb.ScaleTransform(4, 0.25f);
                CheckDefaultRectangle("Scale", pgb.Rectangle);
                pgb.TranslateTransform(-10, -20);
                CheckDefaultRectangle("Translate", pgb.Rectangle);

                pgb.SetBlendTriangularShape(0.5f);
                CheckDefaultRectangle("SetBlendTriangularShape", pgb.Rectangle);
                pgb.SetSigmaBellShape(0.5f);
                CheckDefaultRectangle("SetSigmaBellShape", pgb.Rectangle);
            }
        }
예제 #11
0
        public void Form1_Paint(object sender, PaintEventArgs e)
        {
            //////    // Create a graphics path and add an ellipse.
            //////    GraphicsPath myPath = new GraphicsPath();
            //////    Rectangle rect = new Rectangle(100, 20, 100, 50);
            //////    myPath.AddRectangle(rect);
            //////    // Get the path's array of points.
            //////    PointF[] myPathPointArray = myPath.PathPoints;
            //////    // Create a path gradient brush.
            //////    PathGradientBrush myPGBrush = new
            //////    PathGradientBrush(myPathPointArray);
            //////    // Set the color span.
            //////    myPGBrush.CenterColor = Color.Green;
            //////    Color[] mySurroundColor = { Color.Blue };
            //////    myPGBrush.SurroundColors = mySurroundColor;
            //////    // Draw the brush to the screen prior to transformation.
            //////    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
            //////    // Apply the rotate transform to the brush.
            //////    myPGBrush.RotateTransform(a, MatrixOrder.Append);
            //////    // Draw the brush to the screen again after applying the
            //////    // transform.
            //////    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
            GraphicsPath path = new GraphicsPath(); int Wi = 0; int Hi = 0;

            path.AddEllipse(160, 70, 150, 70);

            // Use the path to construct a brush.
            PathGradientBrush pthGrBrush = new PathGradientBrush(path);

            // Set the color at the center of the path to blue.
            pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);
            //pthGrBrush.FocusScales = new PointF(40, 40);
            // Set the color along the entire boundary
            // of the path to aqua.
            Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
            pthGrBrush.SurroundColors = colors;


            pthGrBrush.RotateTransform(a);

            for (int t = 0; t < 100; t++)
            {
                PointF wq = new PointF(); wq.X = 40; wq.Y = 40; pthGrBrush.TranslateTransform(1, 1); e.Graphics.FillRectangle(pthGrBrush, 0, 0, 700, 700); Invalidate();
            }


            Bitmap bm = new Bitmap(img.Width, img.Height);

            if (a <= 90)
            {
                Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 90 && a <= 180)
            {
                Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 180 && a <= 270)
            {
                Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 270 && a <= 360)
            {
                Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360));
            }
            Bitmap b = new Bitmap(Wi, Hi);



            g.TranslateTransform(Wi / 2, Hi / 2);
            g.RotateTransform(a);
            g.TranslateTransform(-img.Width / 2, -img.Height / 2);

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(img, 0, 0);
            e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
            e.Graphics.DrawImage(b, -b.Width / 2, -b.Height / 2);

            Create the string to draw on the form.
            string text = "Roma prodakshen";

            // Create a GraphicsPath.
            System.Drawing.Drawing2D.GraphicsPath path =
                new System.Drawing.Drawing2D.GraphicsPath();

            // Add the string to the path; declare the font, font style, size, and
            // vertical format for the string.
            path.AddString(text, this.Font.FontFamily, 1, 15,
                           new PointF(100.0F, 50.0F),
                           new StringFormat(StringFormatFlags.DirectionVertical));

            // Declare a matrix that will be used to rotate the text.
            System.Drawing.Drawing2D.Matrix rotateMatrix =
                new System.Drawing.Drawing2D.Matrix();

            // Set the rotation angle and starting point for the text.
            rotateMatrix.RotateAt(a, new PointF(200.0F, 50.0F));

            // Transform the text with the matrix.
            path.Transform(rotateMatrix);

            // Set the SmoothingMode to high quality for best readability.
            e.Graphics.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // Fill in the path to draw the string.
            e.Graphics.FillPath(Brushes.GreenYellow, path);

            // Dispose of the path.
            path.Dispose();
        }