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


C# System.Drawing.Drawing2D.Matrix.Translate方法代码示例

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


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

示例1: DoPaintRemote

 public void DoPaintRemote(PaintEventArgs e)
 {
     var matrix = new System.Drawing.Drawing2D.Matrix();
     matrix.Translate(this.Left, this.Top);
     e.Graphics.Transform = matrix;
     OnPaint(e);
 }
开发者ID:jackmaynard,项目名称:MissionPlanner,代码行数:7,代码来源:DistanceBar.cs

示例2: Area_Paint

        /// <summary>
        /// Draw all areas of the selected quest and highlight the selected area.
        /// </summary>
        private void Area_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Area.BackColor);

            Matrix transformMatrix = new Matrix();
            transformMatrix.Rotate(90);
            transformMatrix.Multiply(new Matrix(-1, 0, 0, 1, 0, 0)); // Flip x-axis

            WoWQuestStep[] steps = ((QuestDisplayData)bsQuests.Current).Steps;

            float maxX = steps.Max(step => step.AreaPoints.Max(ap => ap.X));
            float maxY = steps.Max(step => step.AreaPoints.Max(ap => ap.Y));

            transformMatrix.Translate(-maxX - 5, -maxY - 5);

            e.Graphics.Transform = transformMatrix;

            // Draw all areas
            foreach (WoWQuestStep step in steps)
            {
                PointF[] drawPoints = ConvertToDrawingPoints(step.AreaPoints);
                if (drawPoints.Length < 3)
                {
                    foreach (PointF point in drawPoints)
                    {
                        // Draw a point 5x5 pixels
                        e.Graphics.FillEllipse(AREA_FILL, point.X - 2, point.Y - 2, 5F, 5F);
                        e.Graphics.DrawEllipse(AREA_BORDER, point.X - 2, point.Y - 2, 5F, 5F);
                    }
                }
                else
                {
                    e.Graphics.FillPolygon(AREA_FILL, drawPoints);
                    e.Graphics.DrawPolygon(AREA_BORDER, drawPoints);
                }
            }

            // Highlight selected area
            if (SelectedAreaPoints != null)
            {
                if (SelectedAreaPoints.Length < 3)
                {
                    foreach (PointF point in SelectedAreaPoints)
                    {
                        e.Graphics.FillEllipse(AREA_HIGHLIGHT, point.X - 2, point.Y - 2, 5F, 5F);
                        e.Graphics.DrawEllipse(AREA_BORDER, point.X - 2, point.Y - 2, 5F, 5F);
                    }
                }
                else
                {
                    e.Graphics.FillPolygon(AREA_HIGHLIGHT, this.SelectedAreaPoints);
                    e.Graphics.DrawPolygon(AREA_BORDER, this.SelectedAreaPoints);
                }
            }
        }
开发者ID:Sanjo,项目名称:Honorbuddy-QuestPOI,代码行数:58,代码来源:FormQuestView.cs

示例3: InitializeTransformMatrix

        protected override bool InitializeTransformMatrix()
        {
            if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            StockLog.Write(e);
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            EventSeries.Clear();

            // Create fake Event Series;
            for (int i = 0; i < 5; i++)
            {
               EventSeries.Add(new BoolSerie(this.EndIndex, "Test" + i, i%2 == 0));
            }

            minValue = 0.0f;
            maxValue = EventSeries.Count + 1;

            if (graphic == null)
            {
               // Initialise graphics
               this.graphic = this.CreateGraphics();
               RectangleF rect = this.graphic.VisibleClipBounds;
               rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
               this.GraphRectangle = rect;
            }

            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
             }
             else
             {
            this.Deactivate("App too small...", false);
            return false;
             }
             return true;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:48,代码来源:GraphMutiTimeFrameControl.cs

示例4: InitializeTransformMatrix

        protected override bool InitializeTransformMatrix()
        {
            if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            StockLog.Write(e);
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            minValue = float.MaxValue;
            maxValue = float.MinValue;
            this.CurveList.GetMinMax(StartIndex, EndIndex, ref minValue, ref maxValue, this.ScaleInvisible);

            if (minValue == maxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
            {
               this.Deactivate("No volume for this stock", false);
               return false;
            }
            if (graphic == null)
            {
               // Initialise graphics
               this.graphic = this.CreateGraphics();
               RectangleF rect = this.graphic.VisibleClipBounds;
               rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
               this.GraphRectangle = rect;
            }

            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
             }
             else
             {
            this.Deactivate("App too small...", false);
            return false;
             }
             return true;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:46,代码来源:GraphVolumeControl.cs

示例5: InitializeTransformMatrix

        protected override bool InitializeTransformMatrix()
        {
            if (float.IsNaN(this.RangeMin) || float.IsNaN(this.RangeMax))
             {
            return base.InitializeTransformMatrix();
             }

             if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            throw e;
             }
             if (this.CurveList.GetNbVisible() == 0)
             {
            this.Deactivate("No data to display...", false);
            return false;
             }
             if (this.StartIndex == this.EndIndex || this.EndIndex > this.dateSerie.Length - 1)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("Invalid input data range...");
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            float minValue = this.RangeMin, maxValue = this.RangeMax;
            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
            return true;
             }
             return false;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:40,代码来源:GraphRangedControl.cs

示例6: InitializeTransformMatrix

        protected override bool InitializeTransformMatrix()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return false; }
            if (this.GraphRectangle.Height > 0)
            {
               minValue = float.MaxValue;
               maxValue = float.MinValue;
               this.CurveList.GetMinMax(0, dateSerie.Length - 1, ref minValue, ref maxValue, this.ScaleInvisible);

               if (minValue == maxValue || minValue == float.MaxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || maxValue == float.MinValue || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
               {
                  this.Deactivate("Input data is corrupted and cannot be displayed...", false);
                  return false;
               }

               if (this.IsLogScale && minValue > 0)
               {
                  minValue -= (maxValue - minValue) * 0.025f;
               }
               else
               {
                  minValue -= (maxValue - minValue) * 0.05f;
               }
               maxValue += (maxValue - minValue) * 0.05f;

               float tmpMinValue, tmpMaxValue;
               if (this.IsLogScale)
               {
                  tmpMinValue = minValue < 0 ? (float)-Math.Log10(-minValue + 1) : (float)Math.Log10(minValue + 1);
                  tmpMaxValue = maxValue < 0 ? (float)-Math.Log10(-maxValue + 1) : (float)Math.Log10(maxValue + 1);
               }
               else
               {
                  tmpMinValue = minValue;
                  tmpMaxValue = maxValue;
               }

               float coefX = (this.GraphRectangle.Width * 0.94f) / (dateSerie.Length - 1);
               float coefY = this.GraphRectangle.Height / (tmpMaxValue - tmpMinValue);

               matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
               matrixValueToScreen.Translate(this.GraphRectangle.X + 20, tmpMaxValue * coefY + this.GraphRectangle.Y);
               matrixValueToScreen.Scale(coefX, -coefY);

               matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
               matrixScreenToValue.Invert();
            }
            else
            {
               this.Deactivate("App too small...", false);
               return false;
            }
            return true;
             }
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:57,代码来源:GraphScrollerControl.cs

示例7: UpdateBackBuffer

        /// <summary>
        /// Paints the elements to the backbuffer
        /// </summary>
        private void UpdateBackBuffer()
        {
            _backBuffer = new Bitmap(Width, Height);
            Graphics graph = Graphics.FromImage(_backBuffer);
            graph.SmoothingMode = _drawingQuality;
            graph.FillRectangle(Brushes.White, 0, 0, _backBuffer.Width, _backBuffer.Height);

            //When the backbuffer is updated this code draws the watermark
            if (_showWaterMark)
            {
                Bitmap watermark = Images.MapWindowLogoPale;
                if ((_backBuffer.Width > watermark.Width) && (_backBuffer.Height > watermark.Height))
                {
                    graph.DrawImage(watermark, _backBuffer.Width - watermark.Width - 18, _backBuffer.Height - watermark.Height -18 ,watermark.Width , watermark.Height);
                }
            }

            //Check if there are any model elements to draw
            foreach (ModelElement me in _modelElements)
            {
                if (_modelElementsSelected.Contains(me) == false)
                {
                    System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                    Point translator = VirtualToPixel(new Point(me.Location.X, me.Location.Y));
                    m.Translate(translator.X,translator.Y);
                    m.Scale(_virtualZoom, _virtualZoom);
                    graph.Transform = m;
                    me.Paint(graph);
                    graph.Transform = new System.Drawing.Drawing2D.Matrix();
                }
            }

            //Updates is initialized
            IsInitialized = true;
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:38,代码来源:Modeler.cs

示例8: DrawFillPattern

        private void DrawFillPattern(Graphics g)
        {
            Stopwatch sw = Stopwatch.StartNew();
            float matrixScale;
            var fillPattern = FillPattern;
            if (fillPattern == null)
                return;

            if (fillPattern.Target == FillPatternTarget.Model)
                matrixScale = Scale;
            else
                matrixScale = Scale * 10;

            try
            {
                var width =
                    (ActualWidth == 0 ? Width : ActualWidth) == 0
                    ? 100
                    : (ActualWidth == 0 ? Width : ActualWidth);

                if (double.IsNaN(width))
                    width = 100;

                var height =
                    (ActualHeight == 0 ? Height : ActualHeight) == 0
                    ? 30
                    : (ActualHeight == 0 ? Height : ActualHeight);

                if (double.IsNaN(height))
                    height = 30;

                var viewRect = new Rectangle(0, 0,
                                             (int)width, (int)height);

                var centerX = (viewRect.Left + viewRect.Left
                               + viewRect.Width) / 2;

                var centerY = (viewRect.Top + viewRect.Top
                               + viewRect.Height) / 2;

                g.TranslateTransform(centerX, centerY);

                var rectF = new Rectangle(-1, -1, 2, 2);
                g.FillRectangle(Brushes.Blue, rectF); //draw a small rectangle in the center of the image

                g.ResetTransform();

                var fillGrids = fillPattern.GetFillGrids();

                Debug.Print(new string('-', 100));
                Debug.Print("FilPattern name: {0}", fillPattern.Name);
                if (fillPattern.Target == FillPatternTarget.Model)
                    Debug.Print("FillPattern type: Model");
                else
                    Debug.Print("FillPattern type: Drafting");
                Debug.Print("Matrix scale: {0}", matrixScale);
                Debug.Print("Grids count: {0}", fillGrids.Count);
                Debug.Print("Len\\Area: {0}", fillPattern.LengthPerArea);
                Debug.Print("Lines\\Len: {0}", fillPattern.LinesPerLength);
                Debug.Print("Strokes\\Area: {0}", fillPattern.StrokesPerArea);

                foreach (var fillGrid in fillGrids)
                {
                    var degreeAngle = (float)RadianToGradus(fillGrid.Angle);
                    Debug.Print(new string('-', 50));
                    Debug.Print("Origin: U:{0} V:{1}",
                                fillGrid.Origin.U, fillGrid.Origin.V);
                    Debug.Print("Offset: {0}", fillGrid.Offset);
                    Debug.Print("Angle: {0}", degreeAngle);
                    Debug.Print("Shift: {0}", fillGrid.Shift);

                    var pen = new Pen(System.Drawing.Color.Black)
                    {
                        Width = 1f / matrixScale
                    };

                    float dashLength = 1;
                    var segments = fillGrid.GetSegments();

                    if (segments.Count > 0)
                    {
                        pen.DashPattern = segments
                            .Select(Convert.ToSingle)
                            .ToArray();

                        Debug.Print("\tSegments:");
                        foreach (var segment in segments)
                        {
                            Debug.Print("\t\t{0}", segment);
                        }

                        dashLength = pen.DashPattern.Sum();
                    }

                    g.ResetTransform();
                    var rotateMatrix = new Matrix();
                    rotateMatrix.Rotate(degreeAngle);
                    var matrix = new Matrix(1, 0,
                                            0, -1,
                                            centerX, centerY); //-1 reflects about x-axis
//.........这里部分代码省略.........
开发者ID:kfpopeye,项目名称:AddMaterials,代码行数:101,代码来源:FillPatternViewerControlWpf.xaml.cs

示例9: BisectAngle

			/// <summary>
			/// Bisects the inner angle formed by <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
			/// </summary>
			/// <remarks>
			/// <para>
			/// Based largely on <see cref="ProtractorRoiCalloutLocationStrategy"/>.
			/// </para>
			/// <para>
			/// The return value is a point within the angle such that the line segment
			/// from this point to <paramref name="point2"/> has the specified <paramref name="magnitude"/> and bisects the angle
			/// <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
			/// </para>
			/// </remarks>
			private static PointF BisectAngle(PointF point1, PointF point2, PointF point3, float magnitude)
			{
				PointF[] points = new PointF[] {point1, point3};
				using (Matrix2D rotation = new Matrix2D())
				{
					rotation.Rotate((float) (-Vector.SubtendedAngle(point1, point2, point3)/2 + 180));
					rotation.Translate(-point2.X, -point2.Y);
					rotation.TransformPoints(points);
				}

				Vector3D result = new Vector3D(points[0].X, points[0].Y, 0);
				if (FloatComparer.AreEqual(result.Magnitude, 0F, 0.01F))
					result = new Vector3D(-1, 0, 0);
				result = result/result.Magnitude*magnitude;

				return new PointF(point2.X - result.X, point2.Y - result.Y);
			}
开发者ID:nhannd,项目名称:Xian,代码行数:30,代码来源:ShowAnglesToolGraphic.cs

示例10: OnPaint

        /// <summary>
        /// When the element is called on to be painted this method is called
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
                base.OnPaint(e);
                Bitmap tempBuffer = new Bitmap(Width, Height);
                Graphics tempGraph = Graphics.FromImage(tempBuffer);
                tempGraph.SmoothingMode = _drawingQuality;
                Rectangle inflatedInvalidationRect = Rectangle.Inflate(e.ClipRectangle,5,5);

                if (IsInitialized)
                {
                    tempGraph.DrawImage(_backBuffer, inflatedInvalidationRect, inflatedInvalidationRect, GraphicsUnit.Pixel);
                }
                else
                {
                    UpdateBackBuffer();
                    tempGraph.DrawImage(_backBuffer, new Point(0, 0));
                }

                //Draws selected shapes last 
                if (_modelElementsSelected.Count > 0)
                {
                    for (int i = _modelElementsSelected.Count - 1; i >= 0; i--)
                    {
                        ModelElement me = _modelElementsSelected[i];
                        System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                        Point translator = VirtualToPixel(me.Location.X,me.Location.Y);
                        m.Translate(translator.X, translator.Y);
                        m.Scale(_virtualZoom, _virtualZoom);
                        tempGraph.Transform = m;
                        me.Paint(tempGraph);
                        tempGraph.Transform = new System.Drawing.Drawing2D.Matrix();
                    }
                }

                //If the users is dragging a select box we draw it here
                if (_selectBoxDraw)
                {
                    SolidBrush highlightBrush = new SolidBrush(Color.FromArgb(30,SystemColors.Highlight));
                    tempGraph.FillRectangle(highlightBrush, Rectangle.Inflate(_selectBox,-1,-1));
                    Rectangle outlineRect = new Rectangle(_selectBox.X, _selectBox.Y, _selectBox.Width - 1, _selectBox.Height - 1);
                    tempGraph.DrawRectangle(SystemPens.Highlight, outlineRect);

                    //garbage collection
                    highlightBrush.Dispose();
                }

                //Draws the temporary bitmap to the screen
                e.Graphics.SmoothingMode = _drawingQuality;
                e.Graphics.DrawImage(tempBuffer, inflatedInvalidationRect, inflatedInvalidationRect, GraphicsUnit.Pixel);

                //Garbage collection
                tempBuffer.Dispose();    
                tempGraph.Dispose();
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:58,代码来源:Modeler.cs

示例11: TestMatrix2

            public void TestMatrix2()
            {
                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);

                var at = new AffineCoordinateTransformation2D(mat);
                var atInv = at.Inverse();

                var p0 = new double[] { 50d, 50d };
                var pt = at.Transform(p0);
                at.Invert();
                var p1 = at.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
                var p2 = atInv.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);

                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF ptt = pts[0];
                System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:31,代码来源:ProjectionExamples.cs

示例12: TestAffineTransform2D

            public void TestAffineTransform2D()
            {
                //Setup some affine transformation
                System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.RotateAt(30, new System.Drawing.PointF(0, 0));
                matrix.Translate(-20, -20, System.Drawing.Drawing2D.MatrixOrder.Append);
                matrix.Shear(0.95f, -0.2f, System.Drawing.Drawing2D.MatrixOrder.Append);

                //Create some random sample data
                CreatingData cd = new CreatingData();
                SharpMap.Data.FeatureDataTable fdt1 =
                cd.CreatePointFeatureDataTableFromArrays(GetRandomOrdinates(80, -180, 180),
                                                         GetRandomOrdinates(80, -90, 90), null);

                //Clone random sample data and apply affine transformation on it
                SharpMap.Data.FeatureDataTable fdt2 = TransformedFeatureDataTable(matrix, fdt1);

                //Get affine transformation with LeastSquaresTransform
                SharpMap.Utilities.LeastSquaresTransform lst = new SharpMap.Utilities.LeastSquaresTransform();

                //Add at least three corresponding points
                lst.AddInputOutputPoint(
                ((SharpMap.Data.FeatureDataRow)fdt1.Rows[0]).Geometry as SharpMap.Geometries.Point,
                ((SharpMap.Data.FeatureDataRow)fdt2.Rows[0]).Geometry as SharpMap.Geometries.Point);

                lst.AddInputOutputPoint(
                ((SharpMap.Data.FeatureDataRow)fdt1.Rows[39]).Geometry as SharpMap.Geometries.Point,
                ((SharpMap.Data.FeatureDataRow)fdt2.Rows[39]).Geometry as SharpMap.Geometries.Point);

                lst.AddInputOutputPoint(
                ((SharpMap.Data.FeatureDataRow)fdt1.Rows[79]).Geometry as SharpMap.Geometries.Point,
                ((SharpMap.Data.FeatureDataRow)fdt2.Rows[79]).Geometry as SharpMap.Geometries.Point);

                /*
                //Get affine transformation calculates mean points to improve accuaracy
                //Unfortunately the result is not very good, so, since I know better I manually set these
                //mean points.
                lst.SetMeanPoints(new SharpMap.Geometries.Point(0, 0),
                              new SharpMap.Geometries.Point(matrix.OffsetX, matrix.OffsetY));
                 */

                //Create Affine
                AffineCoordinateTransformation2D at2 = new AffineCoordinateTransformation2D(lst.GetAffineTransformation());

                //Create Map
                SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360));

                //Add not transformed layer
                map.Layers.Add(new SharpMap.Layers.VectorLayer("L1",
                                                           new SharpMap.Data.Providers.GeometryFeatureProvider(fdt1)));
                ((SharpMap.Layers.VectorLayer) map.Layers[0]).Style.Symbol =
                new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");

                //Add transformed layer
                map.Layers.Add(new SharpMap.Layers.VectorLayer("L2",
                                                           new SharpMap.Data.Providers.GeometryFeatureProvider(fdt2)));
                ((SharpMap.Layers.VectorLayer) map.Layers[1]).Style.Symbol =
                new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\women.png");

                //Render map
                map.ZoomToExtents();

                //Get map and save to file
                var bmp = (System.Drawing.Bitmap)map.GetMap();
                bmp.Save("affinetransform1.bmp");

                //we want to reverse the previously applied transformation.
                ((SharpMap.Layers.VectorLayer) map.Layers[1]).CoordinateTransformation = (AffineCoordinateTransformation2D)at2.Inverse();

                //Render map
                map.ZoomToExtents();

                //Get map and save to file
                bmp = (System.Drawing.Bitmap)map.GetMap();
                bmp.Save("affinetransform2.bmp");
                //Hopefully women cover flags ;-).
            }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:77,代码来源:ProjectionExamples.cs

示例13: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {            
            if (dirtyScreenBuf)
            {
                RenderShapefiles();
            }
            if (screenBuf != null)
            {
               // bool selecting = (_panSelectMode != PanSelectMode.Pan);
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                if (_panSelectMode == PanSelectMode.SelectRectangle)
                {
                    e.Graphics.DrawImage(screenBuf, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
                    using (Pen p = new Pen(Color.Red, 1))
                    {
                        using(Brush b = new SolidBrush(Color.FromArgb(20, Color.Red)))
                        {
                            p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                            
                            Rectangle selectRect = new Rectangle(mouseOffPt.X>=0?mouseDownPt.X:mouseDownPt.X+mouseOffPt.X,
                                mouseOffPt.Y>=0?mouseDownPt.Y:mouseDownPt.Y+mouseOffPt.Y,
                                mouseOffPt.X>=0?mouseOffPt.X:-mouseOffPt.X,
                                mouseOffPt.Y>=0?mouseOffPt.Y:-mouseOffPt.Y);
                            
                            e.Graphics.FillRectangle(b, selectRect);
                            e.Graphics.DrawRectangle(p, selectRect);
                        }
                    }
                }
                else if (_panSelectMode == PanSelectMode.SelectCircle)
                {
                    e.Graphics.DrawImage(screenBuf, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
                    using (Pen p = new Pen(Color.Red, 1))
                    {
                        using (Brush b = new SolidBrush(Color.FromArgb(20, Color.Red)))
                        {
                            p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

                            int radius = (int)Math.Round(Math.Sqrt(mouseOffPt.X * mouseOffPt.X + mouseOffPt.Y * mouseOffPt.Y));
                            Rectangle selectRect = new Rectangle(mouseDownPt.X -radius,
                                mouseDownPt.Y -radius,
                                radius*2,
                                radius*2);

                            //e.Graphics.FillRectangle(b, selectRect);
                            //e.Graphics.DrawRectangle(p, selectRect);
                            e.Graphics.FillEllipse(b, selectRect);
                            e.Graphics.DrawEllipse(p, selectRect);
                        }
                    }

                }
                else// if (_panSelectMode == PanSelectMode.Pan)
                {
                    //change this to only draw invalid area
                    if ((mouseOffPt.X == 0) && (mouseOffPt.Y == 0))
                    {
                        e.Graphics.DrawImage(screenBuf, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
                    }
                    else
                    {
                        e.Graphics.DrawImage(screenBuf, mouseOffPt.X, mouseOffPt.Y);
                    }
                }
            }

            System.Drawing.Drawing2D.Matrix m = e.Graphics.Transform;
            try
            {
                System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix();
                m2.Translate(mouseOffPt.X, mouseOffPt.Y);
                e.Graphics.Transform = m2;
                base.OnPaint(e);
            }
            finally
            {
                e.Graphics.Transform = m;
            }
        }
开发者ID:pedrolandaacurio,项目名称:gvix,代码行数:79,代码来源:SFMap.cs

示例14: Draw

        ///// <summary>
        ///// Fires the HighlightChanged event
        ///// </summary>
        ///// <param name="isHighlighted">Specifies the new boolean for whether or not this control is highlighted</param>
        //protected virtual void OnHighlightChanged(bool isHighlighted)
        //{
        //    Invalidate();
        //    if (HighlightChanged != null) HighlightChanged(this, new HighlightEventArgs(isHighlighted));
        //}

        ///// <summary>
        ///// Handles the OnMouseMove event to initialize the Highlight Changed method
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnMouseMove(MouseEventArgs e)
        //{
        //    base.OnMouseMove(e);
        //    IsHighlighted = true;
        //}

        ///// <summary>
        ///// Overrides the base double click behavior to add the navigate functionality
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void OnDoubleClick(EventArgs e)
        //{
        //    OnNavigate(_path);
        //    base.OnDoubleClick(e);
        //}

        ///// <summary>
        ///// Fires the Navigate event
        ///// </summary>
        ///// <param name="path">The string path to navigate to</param>
        //protected virtual void OnNavigate(string path)
        //{
        //    if (Navigate != null) Navigate(this, new NavigateEventArgs(path));
        //}

        /// <summary>
        /// This method instructs this item to draw itself onto the specified graphics surface.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the Graphics object needed for drawing.</param>
        public virtual void Draw(PaintEventArgs e)
        {
            System.Drawing.Drawing2D.Matrix oldMatrix = e.Graphics.Transform;
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Translate(this.Bounds.Left, this.Bounds.Top);
            e.Graphics.Transform = mat;
            OnDraw(e);
            e.Graphics.Transform = oldMatrix;
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:52,代码来源:DirectoryItem.cs

示例15: RotateImage

        public static Image RotateImage(Image inputImg, double degreeAngle)
        {
            //Corners of the image
            PointF[] rotationPoints = { new PointF(0, 0),
                                        new PointF(inputImg.Width, 0),
                                        new PointF(0, inputImg.Height),
                                        new PointF(inputImg.Width, inputImg.Height)};

            //Rotate the corners
            PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle);

            //Get the new bounds given from the rotation of the corners
            //(avoid clipping of the image)
            Rectangle bounds = PointMath.GetBounds(rotationPoints);

            //An empy bitmap to draw the rotated image
            Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);

            using (Graphics g = Graphics.FromImage(rotatedBitmap))
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                //Transformation matrix
                System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f));
                m.Translate(-bounds.Left, -bounds.Top, System.Drawing.Drawing2D.MatrixOrder.Append); //shift to compensate for the rotation

                g.Transform = m;
                g.DrawImage(inputImg, 0, 0);
            }
            return (Image)rotatedBitmap;
        }
开发者ID:chpaul,项目名称:COL_Lib,代码行数:33,代码来源:GlycanImage.cs


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