本文整理汇总了C#中System.Drawing.Drawing2D.Matrix.Shear方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.Matrix.Shear方法的具体用法?C# System.Drawing.Drawing2D.Matrix.Shear怎么用?C# System.Drawing.Drawing2D.Matrix.Shear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.Matrix
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.Matrix.Shear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ;-).
}