System.Drawing.GeomUtilities.CreateGeometricTransform C# (CSharp) Method

CreateGeometricTransform() static private method

This method initializes the new CGAffineTransform such that it represents the geometric transform that maps the rectangle specified by the rect parameter to the parallelogram defined by the three points in the plgpts parameter. The upper-left corner of the rectangle is mapped to the first point in the plgpts array, the upper-right corner is mapped to the second point, and the lower-left corner is mapped to the third point. The lower-right point of the parallelogram is implied by the first three.
static private CreateGeometricTransform ( RectangleF rect, Point points ) : CGAffineTransform
rect RectangleF Rectangle.
points Point Points.
return CGAffineTransform
        internal static CGAffineTransform CreateGeometricTransform(RectangleF rect, Point[] points)
        {
            var p0 = points [0];
            var p1 = points [1];
            var p2 = points [2];

            var width = rect.Width;
            var height = rect.Height;

            float m11 = (p1.X - p0.X) / width;
            float m12 = (p1.Y - p0.Y) / width;
            float m21 = (p2.X - p0.X) / height;
            float m22 = (p2.Y - p0.Y) / height;

            return new CGAffineTransform (m11, m12, m21, m22, p0.X, p0.Y);
        }

Same methods

GeomUtilities::CreateGeometricTransform ( RectangleF rect, PointF points ) : CGAffineTransform

Usage Example

示例#1
0
        /// <summary>
        /// Draws the specified Image at the specified location and with the specified shape and size.
        ///
        /// The destPoints parameter specifies three points of a parallelogram. The three PointF structures
        /// represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth point
        /// is extrapolated from the first three to form a parallelogram.
        ///
        /// The image represented by the image object is scaled and sheared to fit the shape of the parallelogram
        /// specified by the destPoints parameter.
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="destPoints">Destination points.</param>
        public void DrawImage(Image image, PointF [] destPoints)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (destPoints == null)
            {
                throw new ArgumentNullException("destPoints");
            }
            if (destPoints.Length < 3)
            {
                throw new ArgumentException("Destination points must be an array with a length of 3 or 4. " +
                                            "A length of 3 defines a parallelogram with the upper-left, upper-right, " +
                                            "and lower-left corners. A length of 4 defines a quadrilateral with the " +
                                            "fourth element of the array specifying the lower-right coordinate.");
            }

            // Windows throws a Not Implemented error if the points are more than 3
            if (destPoints.Length > 3)
            {
                throw new NotImplementedException();
            }
            if (image.nativeMetafilePage != null)
            {
                throw new NotImplementedException();
            }

            // create our rectangle.  Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there.
            var rect = new CGRect(0, 0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y);

            // We need to flip our Y axis so the image appears right side up
            var geoTransform = new CGAffineTransform(1, 0, 0, -1, 0, rect.Height);

            //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints);
            geoTransform.Multiply(GeomUtilities.CreateGeometricTransform(rect, destPoints));

            // Apply our transform to the context
            context.ConcatCTM(geoTransform);

            // now we draw our image.
            context.DrawImage(rect, image.NativeCGImage);

            // Now we revert our image transform from the context
            var revert = CGAffineTransform.CGAffineTransformInvert(geoTransform);

            context.ConcatCTM(revert);
        }
All Usage Examples Of System.Drawing.GeomUtilities::CreateGeometricTransform