当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Reset方法代码示例

本文整理汇总了C#中System.Drawing.Drawing2D.Matrix.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Reset方法的具体用法?C# Matrix.Reset怎么用?C# Matrix.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Drawing2D.Matrix的用法示例。


在下文中一共展示了Matrix.Reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawEffectImage

        public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel)
        {
            int step = 1;
            Graphics bg;
            Bitmap doubleBufferingBitmap;
            SolidBrush solidBrush;
            Rectangle rectangle;
            Matrix matrix = null;

            try
            {
                doubleBufferingBitmap = new Bitmap(current);        // ダブルバッファリング用画面
                bg = Graphics.FromImage(doubleBufferingBitmap);     // ダブルバッファリング用画面描画用Graphics

                solidBrush = new SolidBrush(System.Drawing.Color.Black);
                rectangle = new Rectangle(0, 0, current.Width, current.Height);
                matrix = new Matrix();

                step = doubleBufferingBitmap.Width / 50;
                if (step < 1)
                {
                    step = 1;
                }

                ResetInterval();

                for (int x = 0; x < doubleBufferingBitmap.Width; x += step)
                {
                    bg.ResetTransform();                        // リセット座標変換
                    bg.FillRectangle(solidBrush, rectangle);

                    // current画像
                    matrix.Reset();
                    matrix.Translate(x, 0, MatrixOrder.Append);    // 原点移動
                    bg.Transform = matrix;                         // 座標設定
                    bg.DrawImage(current, 0, 0);

                    // next画像
                    matrix.Reset();
                    matrix.Translate(x - doubleBufferingBitmap.Width, 0, MatrixOrder.Append);
                    bg.Transform = matrix;
                    bg.DrawImage(next, 0, 0);

                    effecingPanel.pictureBox.Image = doubleBufferingBitmap;
                    effecingPanel.pictureBox.Refresh();

                    DoEventAtIntervals();
                }

                matrix.Dispose();
                bg.Dispose();
                doubleBufferingBitmap.Dispose();

                effecingPanel.pictureBox.Image = next;
            }
            catch (SystemException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:chanpi,项目名称:FormSample,代码行数:60,代码来源:EPL2RSlidingEffect.cs

示例2: Generate

        public static byte[] Generate()
        {
            string captchaString = random.Next(1000, 9999).ToString();
            HttpContext.Current.Session["captcha"] = captchaString;

            Bitmap image = new Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(image);
            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            Matrix matrix = new Matrix();

            for (int i = 0; i < captchaLength; i++)
            {
                matrix.Reset();
                int x = (width / captchaLength) * i;
                int y = height / 2;
                matrix.RotateAt(random.Next(-40, 40), new PointF(x, y));
                graphics.Transform = matrix;
                graphics.DrawString(captchaString[i].ToString(),
                    new Font(FontFamily.GenericSerif, random.Next(25, 40)),
                    new SolidBrush(Color.FromArgb(random.Next(100), random.Next(100), random.Next(100))),
                    x, random.Next(5, 10));
            }

            MemoryStream ms = new MemoryStream();
            image.Save(ms, ImageFormat.Png);

            return ms.GetBuffer();
        }
开发者ID:Dragsaw,项目名称:BreadPunter,代码行数:28,代码来源:Captcha.cs

示例3: OutlinedStringSurface

        public OutlinedStringSurface(
            String str, Font font, Brush brush, Pen outlinePen,
            StringFormat stringFormat)
        {
            Contract.Requires(str != null);
            Contract.Requires(font != null);
            Contract.Requires(brush != null);
            Contract.Requires(outlinePen != null);

            _brush = brush;
            _outlinePen = outlinePen;

            // グラフィックスパスの生成
            _path = new GraphicsPath();
            _path.AddString(
                str, font.FontFamily, (int)font.Style, font.Size,
                new Point(0, 0), stringFormat);
            // サイズを取得する
            var rect = _path.GetBounds();
            Size = rect.Size.ToSize();
            // 描画時にマージンがなくなるように平行移動
            var matrix = new Matrix(1, 0, 0, 1, -rect.Left, -rect.Top);
            _path.Transform(matrix);
            // 描画位置を(0, 0)で記憶
            matrix.Reset();
            _matrix = matrix;
        }
开发者ID:exKAZUu,项目名称:Paraiba,代码行数:27,代码来源:OutlinedStringSurface.cs

示例4: DrawEffectImage

        public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel)
        {
            Bitmap doubleBufferingBitmap = null;    // ダブルバッファリング用画面
            Graphics bg = null;                     // ダブルバッファリング用画面描画用Graphics

            SolidBrush solidBrush = null;
            Rectangle rectangle;
            Matrix matrix = null;

            try
            {
                int deltaDegree = 10;

                doubleBufferingBitmap = new Bitmap(current);
                bg = Graphics.FromImage(doubleBufferingBitmap);

                solidBrush = new SolidBrush(System.Drawing.Color.Black);
                rectangle = new Rectangle(0, 0, current.Width, current.Height);
                matrix = new Matrix();

                ResetInterval();
                for (int angle = 0; angle <= 360; angle += deltaDegree)
                {
                    bg.ResetTransform();                             // リセット座標変換
                    bg.FillRectangle(solidBrush, rectangle);

                    matrix.Reset();
                    matrix.Translate(doubleBufferingBitmap.Width / 2, doubleBufferingBitmap.Height / 2, MatrixOrder.Append);   // 原点移動
                    matrix.Rotate((float)angle);
                    bg.Transform = matrix;                           // 座標設定

                    bg.DrawImage(current, -doubleBufferingBitmap.Width / 2, -doubleBufferingBitmap.Height / 2);  // 画像の中心が(0, 0)になるように描画
                    effecingPanel.pictureBox.Image = doubleBufferingBitmap;
                    effecingPanel.pictureBox.Refresh();

                    Thread.Sleep(20);
                    DoEventAtIntervals();
                }

                matrix.Dispose();
                bg.Dispose();
                doubleBufferingBitmap.Dispose();
            }
            catch(SystemException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:chanpi,项目名称:FormSample,代码行数:48,代码来源:EPRotatingEffect.cs

示例5: Form1_Paint

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = e.Graphics)
            {
                try
                {
                    // рисуем изображение без трасформаций 
                    g.DrawImage(new Bitmap(@"Boxs.bmp"), 0, 0, 100, 100);
                }
                catch { }
                // Создаем матрицу
                Matrix X = new Matrix();
                // Установка трансформаций
                X.RotateAt(45,new Point(150,150));
                X.Translate(100, 100);
                g.Transform = X;
                try
                {
                    // рисуем изображение
                    g.DrawImage(new Bitmap(@"Rings.bmp"), 0, 0, 100, 100);
                }
                catch { }

                // Сброс трансформаций
                X.Reset();
                // Установка трансформаций
                X.RotateAt(25, new Point(50, 150));
                X.Translate(150, 10);
                X.Shear(0.5f, 0.3f);
                g.Transform = X;
                try
                {
                    // рисуем изображение
                    g.DrawImage(new Bitmap(@"Cells.bmp"), 0, 0, 100, 100);
                }
                catch { }

            }

        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:40,代码来源:Form1.cs

示例6: CreateShape

        protected override List<PointF> CreateShape(List<Point> tracePoints)
        {
            Point a = tracePoints[0];
            Point b = tracePoints[tracePoints.Count - 1];
            Point dir = new Point(b.X - a.X, b.Y - a.Y);
            float len = (float)Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y);

            RectangleF rectF;

            if ((ModifierKeys & Keys.Shift) != 0)
            {
                PointF center = new PointF((float)(a.X + b.X) / 2.0f, (float)(a.Y + b.Y) / 2.0f);
                float radius = len / 2;
                rectF = Rectangle.Truncate(Utility.RectangleFromCenter(center, radius));
            }
            else
            {
                rectF = Utility.PointsToRectangle(a, b);
            }

            Rectangle rect = Utility.RoundRectangle(rectF);
            PdnGraphicsPath path = new PdnGraphicsPath();
            path.AddEllipse(rect);

            // Avoid asymmetrical circles where the left or right side of the ellipse has a pixel jutting out
            using (Matrix m = new Matrix())
            {
                m.Reset();
                m.Translate(-0.5f, -0.5f, MatrixOrder.Append);
                path.Transform(m);
            }

            path.Flatten(Utility.IdentityMatrix, 0.1f);

            PointF[] pointsF = path.PathPoints;
            path.Dispose();

            return new List<PointF>(pointsF);
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:39,代码来源:EllipseSelectTool.cs

示例7: MirrorImage

        /// <summary>
        /// Create a mirror of the image in x and/or y
        /// </summary>
        /// <param name="source"></param>
        /// <param name="luminance"></param>
        public static void MirrorImage(Image source, bool xMirror, bool yMirror)
        {
            // get transform values

            float xTransform = (xMirror == true ? -1.0f : 1.0f);

            float yTransform = (yMirror == true ? -1.0f : 1.0f);

            // generate matrix to flip the image based on current settings

            Matrix m = new Matrix();

            m.Reset();

            // we are going to draw the image at the origin so transform so that the origin is at the center of image

            m.Translate((float)source.Width / 2.0f * xTransform, (float)source.Height / 2.0f * yTransform, MatrixOrder.Prepend);

            // scale which flips the image

            m.Scale(xTransform, yTransform, MatrixOrder.Append);

            // get a graphics object for the original image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // set transform into graphics

            g.Transform = m;

            // draw image at origin ( which is now translated to center of window )

            g.DrawImage(source, -((float)source.Width / 2.0f), -((float)source.Height / 2.0f));

            // dispose locals

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:53,代码来源:ImageUtility.cs

示例8: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            int captchaStr = new Random().Next(6, 12);
            context.Session["captcha"] = GenerateRandomString(captchaStr);
            const int iHeight = 70;
            const int iWidth = 250;
            var oRandom = new Random();
            int[] aFontEmSizes = { 15, 20, 25, 30 };
            string[] aFontNames = { "Comic Sans MS", "Arial", "Times New Roman", "Georgia", "Verdana", "Geneva" };

            FontStyle[] aFontStyles =
            {
                FontStyle.Bold,
                FontStyle.Italic,
                FontStyle.Regular,
                FontStyle.Strikeout,
                FontStyle.Underline
            };

            HatchStyle[] aHatchStyles =
            {
                HatchStyle.BackwardDiagonal, HatchStyle.Cross, HatchStyle.DashedDownwardDiagonal, HatchStyle.DashedHorizontal,
                HatchStyle.DashedUpwardDiagonal, HatchStyle.DashedVertical, HatchStyle.DiagonalBrick, HatchStyle.DiagonalCross,
                HatchStyle.Divot, HatchStyle.DottedDiamond, HatchStyle.DottedGrid, HatchStyle.ForwardDiagonal, HatchStyle.Horizontal,
                HatchStyle.HorizontalBrick, HatchStyle.LargeCheckerBoard, HatchStyle.LargeConfetti, HatchStyle.LargeGrid,
                HatchStyle.LightDownwardDiagonal, HatchStyle.LightHorizontal, HatchStyle.LightUpwardDiagonal, HatchStyle.LightVertical,
                HatchStyle.Max, HatchStyle.Min, HatchStyle.NarrowHorizontal, HatchStyle.NarrowVertical, HatchStyle.OutlinedDiamond,
                HatchStyle.Plaid, HatchStyle.Shingle, HatchStyle.SmallCheckerBoard, HatchStyle.SmallConfetti, HatchStyle.SmallGrid,
                HatchStyle.SolidDiamond, HatchStyle.Sphere, HatchStyle.Trellis, HatchStyle.Vertical, HatchStyle.Wave, HatchStyle.Weave,
                HatchStyle.WideDownwardDiagonal, HatchStyle.WideUpwardDiagonal, HatchStyle.ZigZag
            };

            //Get Captcha in Session
            string sCaptchaText = context.Session["captcha"].ToString();

            //Creates an output Bitmap
            var oOutputBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
            var oGraphics = Graphics.FromImage(oOutputBitmap);
            oGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

            //Create a Drawing area
            var oRectangleF = new RectangleF(0, 0, iWidth, iHeight);

            //Draw background (Lighter colors RGB 100 to 255)
            Brush oBrush = new HatchBrush(aHatchStyles[oRandom.Next(aHatchStyles.Length - 1)], Color.Gainsboro, Color.White);//HatchBrush(aHatchStyles[oRandom.Next(aHatchStyles.Length - 1)], Color.FromArgb((oRandom.Next(100, 255)), (oRandom.Next(100, 255)), (oRandom.Next(100, 255))), Color.White);
            oGraphics.FillRectangle(oBrush, oRectangleF);

            var oMatrix = new Matrix();
            int i;
            for (i = 0; i <= sCaptchaText.Length - 1; i++)
            {
                oMatrix.Reset();
                int iChars = sCaptchaText.Length;
                int x = iWidth / (iChars + 1) * i;
                const int y = iHeight / 2;

                //Rotate text Random
                oMatrix.RotateAt(oRandom.Next(-40, 40), new PointF(x, y));
                oGraphics.Transform = oMatrix;

                //Draw the letters with Randon Font Type, Size and Color
                oGraphics.DrawString
                (
                    //Text
                sCaptchaText.Substring(i, 1),
                    //Random Font Name and Style
                new Font(aFontNames[oRandom.Next(aFontNames.Length - 1)], aFontEmSizes[oRandom.Next(aFontEmSizes.Length - 1)], aFontStyles[oRandom.Next(aFontStyles.Length - 1)]),
                    //Random Color (Darker colors RGB 0 to 100)
                new SolidBrush(Color.FromArgb(oRandom.Next(0, 100), oRandom.Next(0, 100), oRandom.Next(0, 100))),
                x,
                oRandom.Next(10, 40)
                );
                oGraphics.ResetTransform();
            }

            context.Response.ContentType = "image/JPEG";
            //render image
            oOutputBitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            //dispose everything, we do not need them any more.
            oOutputBitmap.Dispose();
            oGraphics.Dispose();
            Console.WriteLine();
            context.Response.End();
        }
开发者ID:kshiv4,项目名称:StarX,代码行数:84,代码来源:GenerateRecaptcha.ashx.cs

示例9: ProcessRequest

        //public void ProcessRequest(HttpContext context)
        //{
        //    context.Response.ContentType = "text/plain";
        //    context.Response.Write("Hello World");
        //}
        public void ProcessRequest(HttpContext context)
        {
            const int iHeight = 90;
            const int iWidth = 210;
            var oRandom = new Random();

            var aBackgroundNoiseColor = new int[] { 150, 150, 150 };
            var aTextColor = new int[] { 0, 0, 0 };
            var aFontEmSizes = new[] { 15, 20, 25, 30, 35 };

            var aFontNames = new[]
                                      {
                                          "Comic Sans MS",
                                          "Arial",
                                          "Times New Roman",
                                          "Georgia",
                                          "Verdana",
                                          "Geneva"
                                      };
            var aFontStyles = new[]
                                          {
                                              FontStyle.Bold,
                                              FontStyle.Italic,
                                              FontStyle.Regular,
                                              FontStyle.Strikeout,
                                              FontStyle.Underline
                                          };
            var aHatchStyles = new[]
                                            {
                                                HatchStyle.BackwardDiagonal, HatchStyle.Cross,
                                                HatchStyle.DashedDownwardDiagonal, HatchStyle.DashedHorizontal,
                                                HatchStyle.DashedUpwardDiagonal, HatchStyle.DashedVertical,
                                                HatchStyle.DiagonalBrick, HatchStyle.DiagonalCross,
                                                HatchStyle.Divot, HatchStyle.DottedDiamond, HatchStyle.DottedGrid,
                                                HatchStyle.ForwardDiagonal, HatchStyle.Horizontal,
                                                HatchStyle.HorizontalBrick, HatchStyle.LargeCheckerBoard,
                                                HatchStyle.LargeConfetti, HatchStyle.LargeGrid,
                                                HatchStyle.LightDownwardDiagonal, HatchStyle.LightHorizontal,
                                                HatchStyle.LightUpwardDiagonal, HatchStyle.LightVertical,
                                                HatchStyle.Max, HatchStyle.Min, HatchStyle.NarrowHorizontal,
                                                HatchStyle.NarrowVertical, HatchStyle.OutlinedDiamond,
                                                HatchStyle.Plaid, HatchStyle.Shingle, HatchStyle.SmallCheckerBoard,
                                                HatchStyle.SmallConfetti, HatchStyle.SmallGrid,
                                                HatchStyle.SolidDiamond, HatchStyle.Sphere, HatchStyle.Trellis,
                                                HatchStyle.Vertical, HatchStyle.Wave, HatchStyle.Weave,
                                                HatchStyle.WideDownwardDiagonal, HatchStyle.WideUpwardDiagonal,
                                                HatchStyle.ZigZag
                                            };

            //Get Captcha in Session
            string sCaptchaText = context.Session["Captcha2"].ToString();

            //Creates an output Bitmap
            var oOutputBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
            var oGraphics = Graphics.FromImage(oOutputBitmap);
            oGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

            //Create a Drawing area
            var oRectangleF = new RectangleF(0, 0, iWidth, iHeight);

            //Draw background (Lighter colors RGB 100 to 255)
            Brush oBrush = new HatchBrush(aHatchStyles[oRandom.Next
                                                           (aHatchStyles.Length - 1)], Color.FromArgb((oRandom.Next(100, 255)),
                                                                                                      (oRandom.Next(100, 255)), (oRandom.Next(100, 255))), Color.White);
            oGraphics.FillRectangle(oBrush, oRectangleF);

            var oMatrix = new Matrix();
            int i;
            for (i = 0; i <= sCaptchaText.Length - 1; i++)
            {
                oMatrix.Reset();
                var iChars = sCaptchaText.Length;
                var x = iWidth / (iChars + 1) * i;
                var y = iHeight / 2;

                //Rotate text Random
                oMatrix.RotateAt(oRandom.Next(-40, 40), new PointF(x, y));
                oGraphics.Transform = oMatrix;

                //Draw the letters with Random Font Type, Size and Color
                oGraphics.DrawString
                (
                    //Text
                sCaptchaText.Substring(i, 1),
                    //Random Font Name and Style
                new Font(aFontNames[oRandom.Next(aFontNames.Length - 1)],
                   aFontEmSizes[oRandom.Next(aFontEmSizes.Length - 1)],
                   aFontStyles[oRandom.Next(aFontStyles.Length - 1)]),
                    //Random Color (Darker colors RGB 0 to 100)
                new SolidBrush(Color.FromArgb(oRandom.Next(0, 100),
                   oRandom.Next(0, 100), oRandom.Next(0, 100))),
                x,
                oRandom.Next(10, 40)
                );
                oGraphics.ResetTransform();
//.........这里部分代码省略.........
开发者ID:DiegoTc,项目名称:compiladoresI,代码行数:101,代码来源:CaptchaAdmin.ashx.cs

示例10: GenerateImage

        public VerifyImageInfo GenerateImage(string code, int width, int height, Color bgcolor, int textcolor)
        {
            VerifyImageInfo verifyimage = new VerifyImageInfo();
            verifyimage.ImageFormat = ImageFormat.Jpeg;
            verifyimage.ContentType = "image/pjpeg";

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            Graphics g = Graphics.FromImage(bitmap);
            Rectangle rect = new Rectangle(0, 0, width, height);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            g.Clear(bgcolor);

            int fixedNumber = textcolor == 2 ? 60 : 0;

            SolidBrush drawBrush = new SolidBrush(Color.FromArgb(Next(100), Next(100), Next(100)));
            for (int x = 0; x < 3; x++)
            {
                Pen linePen = new Pen(Color.FromArgb(Next(150) + fixedNumber, Next(150) + fixedNumber, Next(150) + fixedNumber),1);
                g.DrawLine(linePen, new PointF(0.0F + Next(20), 0.0F + Next(height)), new PointF(0.0F + Next(width), 0.0F + Next(height)));
            }

            Matrix m = new Matrix();
            for (int x = 0; x < code.Length; x++)
            {
                m.Reset();
                m.RotateAt(Next(30) - 15, new PointF(Convert.ToInt64(width * (0.10 * x)), Convert.ToInt64(height * 0.5)));
                g.Transform = m;
                drawBrush.Color = Color.FromArgb(Next(150) + fixedNumber + 20, Next(150) + fixedNumber + 20, Next(150) + fixedNumber + 20);
                PointF drawPoint = new PointF(0.0F + Next(4) + x * 20, 3.0F + Next(3));
                g.DrawString(Next(1) == 1 ? code[x].ToString() : code[x].ToString().ToUpper(), fonts[Next(fonts.Length - 1)], drawBrush, drawPoint);
                g.ResetTransform();
            }

            double distort = Next(5, 10) * (Next(10) == 1 ? 1 : -1);

            using (Bitmap copy = (Bitmap)bitmap.Clone())
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int newX = (int)(x + (distort * Math.Sin(Math.PI * y / 84.5)));
                        int newY = (int)(y + (distort * Math.Cos(Math.PI * x / 54.5)));
                        if (newX < 0 || newX >= width)
                            newX = 0;
                        if (newY < 0 || newY >= height)
                            newY = 0;
                        bitmap.SetPixel(x, y, copy.GetPixel(newX, newY));
                    }
                }
            }

            //g.DrawRectangle(new Pen(Color.Silver), 0, 0, bitmap.Width - 1, bitmap.Height - 1);

            drawBrush.Dispose();
            g.Dispose();

            verifyimage.Image = bitmap;

            return verifyimage;
        }
开发者ID:pcstx,项目名称:OA,代码行数:63,代码来源:VerifyImage.cs

示例11: FromRegions

        public static PdnGraphicsPath FromRegions(PdnRegion lhs, CombineMode combineMode, PdnRegion rhs)
        {
            Rectangle lhsBounds = lhs.GetBoundsInt();
            Rectangle rhsBounds = rhs.GetBoundsInt();
            int left = Math.Min(lhsBounds.Left, rhsBounds.Left);
            int top = Math.Min(lhsBounds.Top, rhsBounds.Top);
            int right = Math.Max(lhsBounds.Right, rhsBounds.Right);
            int bottom = Math.Max(lhsBounds.Bottom, rhsBounds.Bottom);
            Rectangle bounds = Rectangle.FromLTRB(left, top, right, bottom);
            BitVector2D stencil = new BitVector2D(bounds.Width, bounds.Height);
            Rectangle[] lhsScans = lhs.GetRegionScansReadOnlyInt();
            Rectangle[] rhsScans = rhs.GetRegionScansReadOnlyInt();

            switch (combineMode)
            {
                case CombineMode.Complement:
                case CombineMode.Intersect:
                case CombineMode.Replace:
                    throw new ArgumentException("combineMode can't be Complement, Intersect, or Replace");

                default:
                    break;
            }

            for (int i = 0; i < lhsScans.Length; ++i)
            {
                Rectangle rect = lhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                stencil.SetUnchecked(rect, true);
            }

            for (int i = 0; i < rhsScans.Length; ++i)
            {
                Rectangle rect = rhsScans[i];
                rect.X -= bounds.X;
                rect.Y -= bounds.Y;

                switch (combineMode)
                {
                    case CombineMode.Xor:
                        stencil.InvertUnchecked(rect);
                        break;

                    case CombineMode.Union:
                        stencil.SetUnchecked(rect, true);
                        break;
                    
                    case CombineMode.Exclude:
                        stencil.SetUnchecked(rect, false);
                        break;
                }
            }

            PdnGraphicsPath path = PathFromStencil(stencil, new Rectangle(0, 0, stencil.Width, stencil.Height));

            using (Matrix matrix = new Matrix())
            {
                matrix.Reset();
                matrix.Translate(bounds.X, bounds.Y);
                path.Transform(matrix);
            }

            return path;
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:66,代码来源:PdnGraphicsPath.cs

示例12: ConvertSweepAngle

		internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem)
		{
			PointF x = new PointF(100, 0);

			PointF[] startVector = new PointF[] { x };
			Matrix rotation = new Matrix();
			rotation.Rotate(startAngle);
			rotation.TransformVectors(startVector);

			PointF[] sweepVector = (PointF[])startVector.Clone();
			rotation.Reset();
			rotation.Rotate(sweepAngle);
			rotation.TransformVectors(sweepVector);
			rotation.Dispose();

			SizeF startVectorTransformed, sweepVectorTransformed;
			if (targetSystem == Graphics.CoordinateSystem.Destination)
			{
				startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0]));
				sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0]));
			}
			else
			{
				startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0]));
				sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0]));
			}

			// simply return the angle between the start and sweep angle, in the target system.
			return (int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF()));
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:30,代码来源:ArcPrimitive.cs

示例13: DoPaintShadow

        /// <summary>
        /// Draws the shape's shadow.
        /// </summary>
        /// <remarks>
        /// The shadow is replaced with a glow.
        /// </remarks>
        protected override void DoPaintShadow(DiagramPaintEventArgs e, IGeometryHost geometryHost)
        {
            Guard.NotNull(() => geometryHost, geometryHost);
            Guard.NotNull(() => e, e);

            Graphics graphics = e.Graphics;
            GraphicsState state = graphics.Save();
            SizeD shadowOffset = this.ShadowOffset;
            try
            {
                GraphicsPath shapePath = this.GetPath(geometryHost);
                RectangleF shapeRectangle = shapePath.GetBounds();

                // Create shadow path
                GraphicsPath shadowPath = shapePath.Clone() as GraphicsPath;

                // Enlarge the shadow (by fixed magnifier amount)
                using (Matrix scaleMatrix = new Matrix())
                {
                    scaleMatrix.Scale(
                        (ShadowMagnifier / shapeRectangle.Width) + 1,
                        (ShadowMagnifier / shapeRectangle.Height) + 1);
                    shadowPath.Transform(scaleMatrix);

                    // Center shadow back on the shape
                    RectangleF shadowRectangle = shadowPath.GetBounds();
                    scaleMatrix.Reset();
                    scaleMatrix.Translate(
                        -((shadowRectangle.X + (shadowRectangle.Width / 2)) - (shapeRectangle.X + (shapeRectangle.Width / 2))),
                        -((shadowRectangle.Y + (shadowRectangle.Height / 2)) - (shapeRectangle.Y + (shapeRectangle.Height / 2))));
                    shadowPath.Transform(scaleMatrix);
                }

                // Set the clip region (on the shape)
                using (Region clip = graphics.Clip)
                {
                    graphics.SetClip(shapePath);

                    // Offset the shadow path (move diagonally down-right) from shape
                    using (Matrix translateMatrix = new Matrix())
                    {
                        translateMatrix.Translate((float)shadowOffset.Width, (float)shadowOffset.Height);
                        shadowPath.Transform(translateMatrix);
                    }

                    // Mask-off the shadow from the original shape
                    graphics.SetClip(shadowPath, CombineMode.Complement);
                    graphics.SetClip(clip, CombineMode.Intersect);

                    // Fill the shadow
                    using (PathGradientBrush shadowBrush = new PathGradientBrush(shadowPath))
                    {
                        shadowBrush.CenterColor = Color.FromArgb(ShadowColorOpacity, ShadowColor);
                        shadowBrush.SurroundColors = new Color[] { Color.Transparent };
                        shadowBrush.FocusScales = new PointF(ShadowGradientFocalPoint, ShadowGradientFocalPoint);
                        graphics.FillPath(shadowBrush, shadowPath);
                        graphics.ResetClip();
                    }
                }
            }
            finally
            {
                graphics.Restore(state);
            }
        }
开发者ID:NuPattern,项目名称:NuPattern,代码行数:71,代码来源:GlowShadowRoundedRectangleShapeGeometry.cs

示例14: OnMouseMove

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!tracking)
            {
                Cursor cursor = this.moveToolCursor;

                for (int i = 0; i < this.moveNubs.Length; ++i)
                {
                    MoveNubRenderer nub = this.moveNubs[i];

                    if (nub.Visible && nub.IsPointTouching(new Point(e.X, e.Y), true))
                    {
                        cursor = this.handCursor;
                        break;
                    }
                }

                this.Cursor = cursor;
            }
            else
            {
                if (this.context.currentMode != Mode.Translate)
                {
                    this.Cursor = this.handCursorMouseDown;
                }

                Point newMouseXY = new Point(e.X, e.Y);
                Point newOffset = new Point(newMouseXY.X - context.startMouseXY.X, newMouseXY.Y - context.startMouseXY.Y);

                PreRender();

                this.dontDrop = true;

                Selection.PerformChanging();

                using (Matrix translateMatrix = new Matrix())
                {
                    RectangleF rect;
                    translateMatrix.Reset();

                    if (this.context.baseTransform != null)
                    {
                        Selection.SetInterimTransform(this.context.baseTransform);
                    }

                    Matrix interim = Selection.GetInterimTransformCopy();

                    switch (this.context.currentMode)
                    {
                        case Mode.Translate:
                            translateMatrix.Translate((float)newOffset.X, (float)newOffset.Y, MatrixOrder.Append);
                            break;

                        case Mode.Rotate:
                            rect = this.context.liftedBounds;
                            PointF center = new PointF(rect.X + (rect.Width / 2.0f), rect.Y + (rect.Height / 2.0f));
                            center = Utility.TransformOnePoint(interim, center);
                            double theta1 = Math.Atan2(context.startMouseXY.Y - center.Y, context.startMouseXY.X - center.X);
                            double theta2 = Math.Atan2(e.Y - center.Y, e.X - center.X);
                            double thetaDelta = theta2 - theta1;
                            this.angleDelta = (float)(thetaDelta * (180.0f / Math.PI));
                            float angle = this.context.startAngle + this.angleDelta;

                            if ((ModifierKeys & Keys.Shift) != 0)
                            {
                                angle = ConstrainAngle(angle);
                                angleDelta = angle - this.context.startAngle;
                            }

                            translateMatrix.RotateAt(angleDelta, center, MatrixOrder.Append);
                            this.rotateNub.Location = center;
                            this.rotateNub.Angle = this.context.startAngle + angleDelta;
                            break;

                        case Mode.Scale:
                            PointF xyAxes = GetEdgeVector(this.context.startEdge);
                            PointF xAxis = new PointF(xyAxes.X, 0);
                            PointF yAxis = new PointF(0, xyAxes.Y);
                            PointF edgeX = Utility.TransformOneVector(interim, xAxis);
                            PointF edgeY = Utility.TransformOneVector(interim, yAxis);
                            PointF edgeXN = Utility.NormalizeVector2(edgeX);
                            PointF edgeYN = Utility.NormalizeVector2(edgeY);

                            PointF xu;
                            float xulen;
                            PointF xv;
                            Utility.GetProjection((PointF)newOffset, edgeXN, out xu, out xulen, out xv);

                            PointF yu;
                            float yulen;
                            PointF yv;
                            Utility.GetProjection((PointF)newOffset, edgeYN, out yu, out yulen, out yv);

                            PdnGraphicsPath startPath2 = this.context.startPath.Clone();
                            RectangleF sp2Bounds = startPath2.GetBounds();

                            PointF sp2BoundsCenter = new PointF((sp2Bounds.Left + sp2Bounds.Right) / 2.0f,
                                (sp2Bounds.Top + sp2Bounds.Bottom) / 2.0f);
//.........这里部分代码省略.........
开发者ID:leejungho2,项目名称:xynotecgui,代码行数:101,代码来源:MoveToolBase.cs

示例15: CreateVerifyCodeImage

        /// <summary>创建验证码图片</summary>
        /// <param name="verifyCodeImageInfo">验证码图片信息</param>
        public void CreateVerifyCodeImage(VerifyCodeImageInfo verifyCodeImageInfo)
        {
            int textLength = verifyCodeImageInfo.Text.Length;
            if(textLength == 0 || verifyCodeImageInfo.ImageWidth == 0 || verifyCodeImageInfo.ImageHeight == 0) return;

            using(var img = new Bitmap(verifyCodeImageInfo.ImageWidth, verifyCodeImageInfo.ImageHeight, PixelFormat.Format32bppArgb))
            {
                using(var g = Graphics.FromImage(img))
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.Clear(verifyCodeImageInfo.BackgroundColor);

                    int charSize = (int)(Math.Min(verifyCodeImageInfo.ImageHeight, (int)(verifyCodeImageInfo.ImageWidth / textLength)) * 0.8);
                    PointF charPoint = new PointF();
                    int halfCharSize = (int)(charSize * 0.5f);
                    int paddingHeight = (int)(verifyCodeImageInfo.ImageHeight * 0.6) - charSize;

                    using(var matrix = new Matrix())
                    {
                        using(var pen = new Pen(Color.Empty))
                        {
                            pen.Width = 1f;
                            using(var b = new SolidBrush(verifyCodeImageInfo.TextColor))
                            {
                                using(var format = new StringFormat())
                                {
                                    format.Alignment = StringAlignment.Near;
                                    format.LineAlignment = StringAlignment.Near;
                                    Font f;
                                    for(int i = 0; i < textLength; i++)
                                    {
                                        // 位置
                                        charPoint.X += i == 0 ? charSize * 0.2f : charSize * 1.1f;// (float)(i * charSize);
                                        charPoint.Y = (float)Utils.Rand(4, paddingHeight);
                                        // 旋转
                                        matrix.Reset();
                                        matrix.RotateAt((float)Utils.Rand(-20, 20),
                                            new PointF(charPoint.X + halfCharSize, charPoint.Y + halfCharSize));
                                        //matrix.Translate(charPoint.X, charPoint.Y);
                                        g.Transform = matrix;

                                        b.Color = pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);

                                        // 字符大小
                                        float fs = charSize * Utils.Rand(80, 120) * 0.01f;
                                        f = new Font(GetFontFamily(verifyCodeImageInfo.Fonts), fs);

                                        g.DrawString(verifyCodeImageInfo.Text[i].ToString(), f, b, charPoint, format);
                                        f.Dispose();
                                        g.ResetTransform();

                                        // 使用字符相同颜色随机绘制曲线
                                        //pen.Width = Utils.Rand(1, 2);
                                        g.DrawBezier(pen,
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight));

                                    }

                                    // 绘制随机纵向曲线
                                    pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);
                                    //pen.Width = Utils.Rand(1, 2);
                                    g.DrawBezier(pen,
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        0,
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        verifyCodeImageInfo.ImageHeight);
                                    // 绘制随机横向曲线
                                    //pen.Width = Utils.Rand(1, 2);
                                    pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);
                                    g.DrawBezier(pen,
                                        0,
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                        Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                        verifyCodeImageInfo.ImageWidth,
                                        Utils.Rand(verifyCodeImageInfo.ImageHeight));

                                }
                            }
                        }
                    }
                }
                verifyCodeImageInfo.ImageData = img.Clone() as Image;
            }
        }
开发者ID:DawangLi,项目名称:NetRube,代码行数:100,代码来源:VerifyCodeImage.cs


注:本文中的System.Drawing.Drawing2D.Matrix.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。