本文整理汇总了C#中Android.Graphics.Path.LineTo方法的典型用法代码示例。如果您正苦于以下问题:C# Path.LineTo方法的具体用法?C# Path.LineTo怎么用?C# Path.LineTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Path
的用法示例。
在下文中一共展示了Path.LineTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
var rect = new RectF(0, 0, 300, 300);
switch (Shape)
{
case Shape.Circle:
canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue });
break;
case Shape.Square:
canvas.DrawRect(rect, new Paint() { Color = Color.Crimson });
break;
case Shape.Triangle:
var path = new Path();
path.MoveTo(rect.CenterX(), rect.Top);
path.LineTo(rect.Left, rect.Bottom);
path.LineTo(rect.Right, rect.Bottom);
path.Close();
var paint = new Paint() {Color = Color.Crimson};
paint.Color = Color.Gold;
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
示例2: Draw
public override void Draw(Android.Graphics.Canvas canvas)
{
base.Draw(canvas);
var rect = new RectF(0,0,300,300);
switch (TheShape)
{
case Shape.Circle:
canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
break;
case Shape.Square:
canvas.DrawRect(rect, new Paint() { Color = Color.Red });
break;
case Shape.Triangle:
var path = new Path();
path.MoveTo(rect.CenterX(), 0);
path.LineTo(0, rect.Height());
path.LineTo(rect.Width(), rect.Height());
path.Close();
var paint = new Paint() {Color = Color.Magenta};
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
示例3: DrawShape
protected void DrawShape(Canvas canvas)
{
Paint paint = new Paint();
paint.Color = Color;
switch (Shape)
{
case ShapeEnum.RectangleShape:
canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint);
break;
case ShapeEnum.OvalShape:
canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint);
break;
case ShapeEnum.TriangleShape:
Path path = new Path();
path.MoveTo(ShapeWidth / 2, 0);
path.LineTo(ShapeWidth, ShapeHeight);
path.LineTo(0,ShapeHeight);
path.Close();
canvas.DrawPath(path, paint);
break;
default:
canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint);
break;
}
}
示例4: Draw
/// <Docs>The Canvas to which the View is rendered.</Docs>
/// <summary>
/// BoxViewのカスタマイズはDrawで行う
/// </summary>
/// <param name="canvas">Canvas.</param>
public override void Draw(Android.Graphics.Canvas canvas)
{
// 2重に描画してしまうので、baseは描画しない
//base.Draw(canvas);
// ElementをキャストしてFormsで定義したCustomBoxViewを取得
var formsBox = (CustomBoxView)Element;
// Androidの描画はPaintを使用
using (var paint = new Paint())
{
// 塗りつぶし色の設定
paint.Color = formsBox.FillColor.ToAndroid();
// 吹き出し部分の設定
// パスの生成
var path = new Path();
// スタート地点の設定
path.MoveTo(0, 0);
// 経由地点の設定
path.LineTo(100, 10);
path.LineTo(100, 100);
// パスを繋げる
path.Close();
// 描画
canvas.DrawPath(path, paint);
// 角の丸い四角の設定
// 角丸の直径を決める
// widthとheightを比較して小さい方を基準にする
var minSize = Math.Min(Width, Height);
// 指定するのは直径なので、指定半径を2倍する
var diameter = formsBox.Radius * 2;
// 角丸の直径はminSize以下でなければならない
if (diameter > minSize)
diameter = minSize;
// 描画領域の設定
var rect = new RectF(0, 0, (float)Width, (float)Height);
//四角形描画
canvas.DrawRoundRect(rect, diameter, diameter, paint);
}
}
示例5: parse
internal static Path parse(float[] pPoints) {
Path path = new Path();
path.MoveTo(pPoints[0], pPoints[1]);
for (int i = 2; i < pPoints.Length; i += 2) {
float x = pPoints[i];
float y = pPoints[i + 1];
path.LineTo(x, y);
}
return path;
}
示例6: Initialize
public void Initialize()
{
_minuteHand = new Path();
_minuteHand.MoveTo(0, 10);
_minuteHand.LineTo(0, -55);
_minuteHand.Close();
_secondHand = new Path();
_secondHand.MoveTo(0, -80);
_secondHand.LineTo(0, 15);
_secondHand.Close();
}
示例7: Initialize
void Initialize ()
{
// Create Paint for all drawing
paint = new Paint ();
// All paths are based on 100-unit clock radius
// centered at (0, 0).
// Define circle for tick marks.
tickMarks = new Path ();
tickMarks.AddCircle (0, 0, 90, Path.Direction.Cw);
// Hour, minute, second hands defined to point straight up.
// Define hour hand.
hourHand = new Path ();
hourHand.MoveTo (0, -60);
hourHand.CubicTo (0, -30, 20, -30, 5, -20);
hourHand.LineTo (5, 0);
hourHand.CubicTo (5, 7.5f, -5, 7.5f, -5, 0);
hourHand.LineTo (-5, -20);
hourHand.CubicTo (-20, -30, 0, -30, 0, -60);
hourHand.Close ();
// Define minute hand.
minuteHand = new Path ();
minuteHand.MoveTo (0, -80);
minuteHand.CubicTo (0, -75, 0, -70, 2.5f, -60);
minuteHand.LineTo (2.5f, 0);
minuteHand.CubicTo (2.5f, 5, -2.5f, 5, -2.5f, 0);
minuteHand.LineTo (-2.5f, -60);
minuteHand.CubicTo (0, -70, 0, -75, 0, -80);
minuteHand.Close ();
// Define second hand.
secondHand = new Path ();
secondHand.MoveTo (0, 10);
secondHand.LineTo (0, -80);
}
示例8: Calculate
private Path Calculate(int size, Direction direction)
{
Point p1, p2, p3;
if (direction == Direction.Up)
{
p1 = new Point(0, size);
p2 = new Point(size, size);
p3 = new Point(size / 2, 0);
}
else
{
p1 = new Point(0, 0);
p2 = new Point(size, 0);
p3 = new Point(size / 2, size);
}
var path = new Path();
path.MoveTo(p1.X, p1.Y);
path.LineTo(p2.X, p2.Y);
path.LineTo(p3.X, p3.Y);
return path;
}
示例9: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
var path = new Path();
path.MoveTo(_points[0].X, _points[0].Y);
for (var i = 1; i < _points.Length; i++)
{
path.LineTo(_points[i].X, _points[i].Y);
}
var paint = new Paint
{
Color = Color.White
};
// We can use Paint.Style.Stroke if we want to draw a "hollow" polygon,
// But then we had better set the .StrokeWidth property on the paint.
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
}
示例10: ToTransformedCorners
public static Bitmap ToTransformedCorners(Bitmap source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize,
CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio)
{
double sourceWidth = source.Width;
double sourceHeight = source.Height;
double desiredWidth = sourceWidth;
double desiredHeight = sourceHeight;
double desiredRatio = cropWidthRatio / cropHeightRatio;
double currentRatio = sourceWidth / sourceHeight;
if (currentRatio > desiredRatio)
{
desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
}
else if (currentRatio < desiredRatio)
{
desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
}
topLeftCornerSize = topLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
topRightCornerSize = topRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
bottomLeftCornerSize = bottomLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
bottomRightCornerSize = bottomRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
float cropX = (float)((sourceWidth - desiredWidth) / 2);
float cropY = (float)((sourceHeight - desiredHeight) / 2);
Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
using (Matrix matrix = new Matrix())
using (var path = new Path())
{
if (cropX != 0 || cropY != 0)
{
matrix.SetTranslate(-cropX, -cropY);
shader.SetLocalMatrix(matrix);
}
paint.SetShader(shader);
paint.AntiAlias = true;
// TopLeft
if (cornersTransformType.HasFlag(CornerTransformType.TopLeftCut))
{
path.MoveTo(0, (float)topLeftCornerSize);
path.LineTo((float)topLeftCornerSize, 0);
}
else if (cornersTransformType.HasFlag(CornerTransformType.TopLeftRounded))
{
path.MoveTo(0, (float)topLeftCornerSize);
path.QuadTo(0, 0, (float)topLeftCornerSize, 0);
}
else
{
path.MoveTo(0, 0);
}
// TopRight
if (cornersTransformType.HasFlag(CornerTransformType.TopRightCut))
{
path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
path.LineTo((float)desiredWidth, (float)topRightCornerSize);
}
else if (cornersTransformType.HasFlag(CornerTransformType.TopRightRounded))
{
path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
path.QuadTo((float)desiredWidth, 0, (float)desiredWidth, (float)topRightCornerSize);
}
else
{
path.LineTo((float)desiredWidth ,0);
}
// BottomRight
if (cornersTransformType.HasFlag(CornerTransformType.BottomRightCut))
{
path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
path.LineTo((float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
}
else if (cornersTransformType.HasFlag(CornerTransformType.BottomRightRounded))
{
path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
path.QuadTo((float)desiredWidth, (float)desiredHeight, (float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
}
else
{
path.LineTo((float)desiredWidth, (float)desiredHeight);
}
// BottomLeft
if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftCut))
{
path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
path.LineTo(0, (float)(desiredHeight - bottomLeftCornerSize));
}
//.........这里部分代码省略.........
示例11: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw (canvas);
if (GraphicMode) {
for (int x = 0; x < xMax; x += 1)
for (int y = 0; y < yMax; y += 1)
if (gameObjects [x, y] > 0)
canvas.DrawBitmap (bitmaps [(int)gameObjects [x, y]],
xBalance + x * objectSize,
yBalance + y * objectSize,
paint);
} else {
if (_wallPoints != null) {
var path = new Path ();
foreach (PointF[] _point in _wallPoints) {
path.MoveTo (_point [0].X, _point [0].Y);
for (var i = 1; i < _point.Length; i++) {
path.LineTo (_point [i].X, _point [i].Y);
}
}
var paint = new Paint {
Color = Color.Brown
};
paint.SetStyle (Paint.Style.Fill);
canvas.DrawPath (path, paint);
}
if (_applePoints != null) {
var path = new Path ();
foreach (PointF[] _point in _applePoints) {
path.MoveTo (_point [0].X, _point [0].Y);
for (var i = 1; i < _point.Length; i++) {
path.LineTo (_point [i].X, _point [i].Y);
}
}
var paint = new Paint {
Color = Color.Red
};
paint.SetStyle (Paint.Style.Fill);
canvas.DrawPath (path, paint);
}
if (_snakePoints != null) {
var path = new Path ();
foreach (PointF[] _point in _snakePoints) {
path.MoveTo (_point [0].X, _point [0].Y);
for (var i = 1; i < _point.Length; i++) {
path.LineTo (_point [i].X, _point [i].Y);
}
}
var paint = new Paint {
Color = Color.LawnGreen
};
paint.SetStyle (Paint.Style.Fill);
canvas.DrawPath (path, paint);
}
}
}
示例12: OnDraw
//.........这里部分代码省略.........
//Is left side is outside the screen
if (bound.Left < leftClip) {
float w = bound.Right - bound.Left;
//Try to clip to the screen (left side)
ClipViewOnTheLeft(bound, w, left);
//Except if there's an intersection with the right view
RectF rightBound = bounds[i + 1];
//Intersection
if (bound.Right + mTitlePadding > rightBound.Left) {
bound.Left = rightBound.Left - w - mTitlePadding;
bound.Right = bound.Left + w;
}
}
}
}
//Right views starting from the current position
if (mCurrentPage < countMinusOne) {
for (int i = mCurrentPage + 1 ; i < count; i++) {
RectF bound = bounds[i];
//If right side is outside the screen
if (bound.Right > rightClip) {
float w = bound.Right - bound.Left;
//Try to clip to the screen (right side)
ClipViewOnTheRight(bound, w, right);
//Except if there's an intersection with the left view
RectF leftBound = bounds[i - 1];
//Intersection
if (bound.Left - mTitlePadding < leftBound.Right) {
bound.Left = leftBound.Right + mTitlePadding;
bound.Right = bound.Left + w;
}
}
}
}
//Now draw views
//int colorTextAlpha = mColorText >>> 24;
int colorTextAlpha = mColorText >> 24;
for (int i = 0; i < count; i++) {
//Get the title
RectF bound = bounds[i];
//Only if one side is visible
if ((bound.Left > left && bound.Left < right) || (bound.Right > left && bound.Right < right)) {
bool currentPage = (i == page);
//Only set bold if we are within bounds
mPaintText.FakeBoldText = (currentPage && currentBold && mBoldText);
//Draw text as unselected
mPaintText.Color = (mColorText);
if(currentPage && currentSelected) {
//Fade out/in unselected text as the selected text fades in/out
mPaintText.Alpha = (colorTextAlpha - (int)(colorTextAlpha * selectedPercent));
}
canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText);
//If we are within the selected bounds draw the selected text
if (currentPage && currentSelected) {
mPaintText.Color = mColorSelected;
mPaintText.Alpha = ((int)((mColorSelected >> 24) * selectedPercent));
canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText);
}
}
}
//Draw the footer line
mPath = new Path();
mPath.MoveTo(0, height - mFooterLineHeight / 2f);
mPath.LineTo(width, height - mFooterLineHeight / 2f);
mPath.Close();
canvas.DrawPath(mPath, mPaintFooterLine);
switch (mFooterIndicatorStyle) {
case IndicatorStyle.Triangle:
mPath = new Path();
mPath.MoveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight);
mPath.LineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight);
mPath.LineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight);
mPath.Close();
canvas.DrawPath(mPath, mPaintFooterIndicator);
break;
case IndicatorStyle.Underline:
if (!currentSelected || page >= boundsSize) {
break;
}
RectF underlineBounds = bounds[page];
mPath = new Path();
mPath.MoveTo(underlineBounds.Left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
mPath.LineTo(underlineBounds.Left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
mPath.Close();
mPaintFooterIndicator.Alpha = ((int)(0xFF * selectedPercent));
canvas.DrawPath(mPath, mPaintFooterIndicator);
mPaintFooterIndicator.Alpha = (0xFF);
break;
}
}
示例13: OnCreateView
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the interpolator_fragment layout
var v = inflater.Inflate (Resource.Layout.interpolator_fragment, container, false);
// Set up the "animate" button
// When it is clicked, the view is animatied with the options selected
var button = v.FindViewById<Button> (Resource.Id.animateButton);
button.Click += delegate {
// Interpolator selected in the spinner
var interpolator = interpolators [interpolatorSpinner.SelectedItemPosition];
// Duration selected in SeekBar
long duration = (long)durationSeekbar.Progress;
// Animation path is based on whether animating in or out
var path = isOut ? pathIn : pathOut;
// Log animation details
Log.Info (TAG, string.Format ("Starting animation: [{0} ms, {1}, {2}",
duration, interpolatorSpinner.SelectedItem.ToString (),
((isOut) ? "Out (growing)" : "In (shrinking)")));
// Start the animation with the selected options
StartAnimation(interpolator,duration,path);
// Toggle direction of the animation
isOut = !isOut;
};
durationLabel = v.FindViewById<TextView> (Resource.Id.durationLabel);
// Initialize the Interpolators programmatically by loading them from their XML definitions
// provided by the framework.
interpolators = new IInterpolator[]
{
AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.Linear),
AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.FastOutLinearIn),
AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.FastOutSlowIn),
AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.LinearOutSlowIn)
};
// Load names of interpolators
var interpolatorNames = Resources.GetStringArray (Resource.Array.interpolator_names);
// Set up the Spinner with the names of interpolators
interpolatorSpinner = v.FindViewById<Spinner> (Resource.Id.interpolatorSpinner);
var spinnerAdapter = new ArrayAdapter<string> (Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, interpolatorNames);
interpolatorSpinner.Adapter = spinnerAdapter;
// Set up SeekBar that defines the duration of the animation
durationSeekbar = v.FindViewById<SeekBar> (Resource.Id.durationSeek);
durationSeekbar.ProgressChanged+=delegate {
durationLabel.SetText(Resources.GetString(Resource.String.animation_duration,durationSeekbar.Progress),TextView.BufferType.Normal);
};
// Set default duration
durationSeekbar.Progress = INITIAL_DURATION_MS;
// Get the view that will be animated
view = v.FindViewById (Resource.Id.square);
// Path for the "in" animation
pathIn = new Path ();
pathIn.MoveTo (0.2f, 0.2f);
pathIn.LineTo (1f, 1f);
// Path for the "out" animation
pathOut = new Path ();
pathOut.MoveTo (1f, 1f);
pathOut.LineTo (0.2f, 0.2f);
return v;
}
示例14: drawPolygonInCanvas
private static void drawPolygonInCanvas(Canvas canvas, PointF[] polygon, Color color)
{
var path = new Path();
// Set the first point, that the drawing will start from.
path.MoveTo(polygon[0].X, polygon[0].Y);
for (var i = 1; i < polygon.Length; i++)
{
// Draw a line from the previous point in the path to the new point.
path.LineTo(polygon[i].X, polygon[i].Y);
}
Paint paint = new Paint {
AntiAlias = true,
Color = color
};
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
paint.Dispose();
}
示例15: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw (canvas);
var r = new Rect (0,0,canvas.Width,canvas.Height);
float dAdjustedThicnkess = (float)this.Thickness * dm;
var paint = new Paint()
{
Color = this.StrokeColor,
StrokeWidth = dAdjustedThicnkess,
AntiAlias = true
};
paint.SetStyle(Paint.Style.Stroke);
switch(StrokeType) {
case StrokeType.Dashed:
paint.SetPathEffect(new DashPathEffect(new float[]{ 6*dm, 2*dm}, 0));
break;
case StrokeType.Dotted:
paint.SetPathEffect(new DashPathEffect(new float[]{ dAdjustedThicnkess, dAdjustedThicnkess}, 0));
break;
default:
break;
}
var desiredTotalSpacing = (SpacingAfter + SpacingBefore)*dm;
float leftForSpacing = 0;
float actualSpacingBefore = 0;
float actualSpacingAfter = 0;
if(Orientation == SeparatorOrientation.Horizontal){
leftForSpacing = r.Height() - dAdjustedThicnkess;
}else{
leftForSpacing = r.Width() - dAdjustedThicnkess;
}
if(desiredTotalSpacing > 0) {
float spacingCompressionRatio = (float)(leftForSpacing / desiredTotalSpacing) ;
actualSpacingBefore = (float)SpacingBefore*dm * spacingCompressionRatio;
actualSpacingAfter = (float)SpacingAfter*dm * spacingCompressionRatio;
}else{
actualSpacingBefore = 0;
actualSpacingAfter = 0;
}
float thicknessOffset = (dAdjustedThicnkess)/2.0f;
Path p = new Path();
if(Orientation == SeparatorOrientation.Horizontal){
p.MoveTo(0, actualSpacingBefore + thicknessOffset);
p.LineTo(r.Width(), actualSpacingBefore + thicknessOffset);
}else{
p.MoveTo(actualSpacingBefore+thicknessOffset, 0);
p.LineTo(actualSpacingBefore+thicknessOffset, r.Height());
}
canvas.DrawPath(p, paint);
}