本文整理汇总了C#中System.Drawing.Rectangle.Center方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Center方法的具体用法?C# Rectangle.Center怎么用?C# Rectangle.Center使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Center方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DepthToSkeleton
public static SkeletonPoint DepthToSkeleton(Rectangle rect, byte[,,] depthData, int width,
int height, CoordinateConverter mapper)
{
var aveDepth = 0.0;
var count = 0;
for (int y = rect.Top; y < rect.Top + rect.Height && y < height; y++)
for (int x = rect.Left; x < rect.Left + rect.Width && x < width; x++) {
if (x > 0 && y > 0) {
aveDepth += depthData[y, x, 0];
count++;
}
}
var depth = PlayerDetector.ToWorldDepth(aveDepth / count);
var center = rect.Center();
var centerX = Math.Max(0, center.X);
centerX = Math.Min(centerX, width);
var centerY = Math.Max(0, center.Y);
centerY = Math.Min(centerY, height);
return mapper.MapDepthPointToSkeletonPoint((int)centerX, (int)centerY, depth);
}
示例2: NormalizePoints
public static void NormalizePoints(Point[] points, Rectangle rectangle)
{
if (rectangle.Height == 0 || rectangle.Width == 0)
return;
Matrix m = new Matrix();
m.Translate(rectangle.Center().X, rectangle.Center().Y);
if (rectangle.Width > rectangle.Height)
m.Scale(1, 1f * rectangle.Width / rectangle.Height);
else
m.Scale(1f * rectangle.Height / rectangle.Width, 1);
m.Translate(-rectangle.Center().X, -rectangle.Center().Y);
m.TransformPoints(points);
}
示例3: CreateTailPath
protected GraphicsPath CreateTailPath(Rectangle rect, Point tailPosition)
{
GraphicsPath gpTail = new GraphicsPath();
Point center = rect.Center();
int rectAverageSize = (rect.Width + rect.Height) / 2;
int tailWidth = (int)(TailWidthMultiplier * rectAverageSize);
tailWidth = Math.Min(Math.Min(tailWidth, rect.Width), rect.Height);
int tailOrigin = tailWidth / 2;
int tailLength = (int)MathHelpers.Distance(center, tailPosition);
gpTail.AddLine(0, -tailOrigin, 0, tailOrigin);
gpTail.AddLine(0, tailOrigin, tailLength, 0);
gpTail.CloseFigure();
using (Matrix matrix = new Matrix())
{
matrix.Translate(center.X, center.Y);
float tailDegree = MathHelpers.LookAtDegree(center, tailPosition);
matrix.Rotate(tailDegree);
gpTail.Transform(matrix);
}
return gpTail;
}
示例4: GetSplitModeImageRectangles
/// <summary>
/// Retrieves the rectangles in which images should be placed in side-by-side mode
/// </summary>
public static void GetSplitModeImageRectangles(Rectangle clientRectangle, Size maxImageSize, out Rectangle rectangle1, out Rectangle rectangle2)
{
var halfRectangle = new Rectangle(clientRectangle.X, clientRectangle.Y, clientRectangle.Width / 2, clientRectangle.Height);
var imageSize = maxImageSize.ConstrainedTo(halfRectangle.Size);
var center1 = halfRectangle.Center();
var center2 = new Point(center1.X + halfRectangle.Width, center1.Y);
rectangle1 = new Rectangle(imageSize.CenteredAround(center1), imageSize);
rectangle2 = new Rectangle(imageSize.CenteredAround(center2), imageSize);
if (rectangle1.X - clientRectangle.X > MIN_BORDER)
{
int shift = rectangle1.X - clientRectangle.X - MIN_BORDER;
rectangle1.X -= shift;
rectangle2.X += shift;
}
}
示例5: DrawArrow
/// <summary>
/// Draws an arrow in the specified rectangle with the specified direction. Ratio is used on recursive calls
/// withing this function to adjust the sizing of bidirectional arrows
/// </summary>
public static void DrawArrow(this Graphics graphics, Rectangle area, ArrowType arrowType, double ratio = 1.0 / 3.0)
{
if (arrowType == ArrowType.Bidi)
{
var halfSize = new Size(area.Width / 2, area.Height);
graphics.DrawArrow(new Rectangle(area.Location, halfSize), ArrowType.Left, 2 * ratio);
graphics.DrawArrow(new Rectangle(new Point(area.Center().X, area.Location.Y), halfSize), ArrowType.Right, 2 * ratio);
return;
}
var oldMode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
float bodyHeight = area.Height / 3;
float headWidth = (area.Width * ratio).Rounded();
float bodyWidth = area.Width - headWidth;
PointF[] points =
{
new PointF(area.Left, area.Top + bodyHeight),
new PointF(area.Left + bodyWidth, area.Top + bodyHeight),
new PointF(area.Left + bodyWidth, area.Top),
new PointF(area.Right, area.Top + (area.Height / 2)),
new PointF(area.Left + bodyWidth, area.Bottom),
new PointF(area.Left + bodyWidth, area.Bottom - bodyHeight),
new PointF(area.Left, area.Bottom - bodyHeight),
};
if (arrowType == ArrowType.Left)
{
PointF center = area.Center();
for (int i = 0; i < points.Length; i++)
points[i].X += (2 * (center.X - points[i].X));
}
using (GraphicsPath path = new GraphicsPath())
{
path.AddPolygon(points);
graphics.FillPath(Brushes.Black, path);
graphics.DrawPath(crossPen, path);
}
graphics.SmoothingMode = oldMode;
}
示例6: Tick
protected override void Tick(Graphics graphics, Rectangle camera)
{
graphics.DrawImageUnscaled(_boardBitmap, -camera.X, -camera.Y);
var center = camera.Center();
var screencenter = new Vector2(camera.Width / 2.0f, camera.Height / 2.0f);
foreach (var pointable in EntitiesOfType<IPointable>())
{
var delta = pointable.Position - center;
var dist = Math.Min(camera.Width, camera.Height) / 2 - 10;
if (Math.Abs(delta.X) > dist || Math.Abs(delta.Y) > dist)
{
graphics.DrawPolygon(pointable.Pen, new[]
{
(screencenter + delta.Normalized * dist).Point,
(screencenter + Vector2.FromTheta(delta.Theta + 0.2f) * dist).Point,
(screencenter + Vector2.FromTheta(delta.Theta - 0.2f) * dist).Point
});
}
}
}