本文整理汇总了C#中Android.Graphics.Canvas.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.Rotate方法的具体用法?C# Canvas.Rotate怎么用?C# Canvas.Rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.Rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw(Canvas canvas)
{
canvas.Save();
if (RotationPivotPoint != null) {
canvas.Rotate(RotationDegress, RotationPivotPoint.X, RotationPivotPoint.Y);
} else {
canvas.Rotate(RotationDegress);
}
base.OnDraw(canvas);
}
示例2: Draw
public void Draw(Canvas canvas)
{
canvas.Save();
canvas.Translate((float)Position.X, (float)Position.Y);
canvas.Rotate((float)Acceleration.Direction + ROTATION_OFFSET);
mDrawable.Draw(canvas);
canvas.Restore();
}
示例3: ToRotatedBitmap
public static Bitmap ToRotatedBitmap(this Bitmap sourceBitmap, int rotationDegrees)
{
if (rotationDegrees == 0)
return sourceBitmap;
int width = sourceBitmap.Width;
int height = sourceBitmap.Height;
if (rotationDegrees == 90 || rotationDegrees == 270)
{
width = sourceBitmap.Height;
height = sourceBitmap.Width;
}
Bitmap bitmap = Bitmap.CreateBitmap(width, height, sourceBitmap.GetConfig());
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
using (BitmapShader shader = new BitmapShader(sourceBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
using (Matrix matrix = new Matrix())
{
// paint.AntiAlias = true;
// paint.Dither = true;
// paint.FilterBitmap = true;
canvas.Save(Android.Graphics.SaveFlags.Matrix);
if (rotationDegrees == 90)
canvas.Rotate(rotationDegrees, width / 2, width / 2);
else if (rotationDegrees == 270)
canvas.Rotate(rotationDegrees, height / 2, height / 2);
else
canvas.Rotate(rotationDegrees, width / 2, height / 2);
canvas.DrawBitmap(sourceBitmap, matrix, paint);
canvas.Restore();
}
if (sourceBitmap != null && sourceBitmap.Handle != IntPtr.Zero && !sourceBitmap.IsRecycled)
{
sourceBitmap.Recycle();
sourceBitmap.Dispose();
}
return bitmap;
}
示例4: DispatchDraw
// Rotate the canvas before drawing
protected override void DispatchDraw(Canvas canvas)
{
canvas.Save (SaveFlags.Matrix);
canvas.Rotate (-heading, Width * 0.5f, Height * 0.5f);
base.DispatchDraw (canvas);
canvas.Restore ();
}
示例5: Draw
public override void Draw(Canvas canvas, ICharSequence text, Int32 start, Int32 end, Single x, Int32 top, Int32 y, Int32 bottom, Paint paint)
{
ApplyCustomTypeFace(paint, _type);
paint.GetTextBounds(_icon, 0, 1, TEXT_BOUNDS);
canvas.Save();
var baselineRatio = _baselineAligned ? 0f : BASELINE_RATIO;
if (_rotate)
{
var rotation = (SystemClock.CurrentThreadTimeMillis() - _rotationStartTime) / (Single)ROTATION_DURATION * 360f;
var centerX = x + TEXT_BOUNDS.Width() / 2f;
var centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
canvas.Rotate(rotation, centerX, centerY);
}
canvas.DrawText(_icon, x - TEXT_BOUNDS.Left, y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
canvas.Restore();
}
示例6: Draw
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y,
int bottom, Paint paint)
{
ApplyCustomTypeFace(paint, _typeface);
paint.GetTextBounds(_icon, 0, 1, TextBounds);
canvas.Save();
if (_rotate)
{
var rotation = (DateTimeHelpers.CurrentUnixTimeMillis() - _rotationStartTime)/(float) RotationDuration*
360f;
var centerX = x + TextBounds.Width()/2f;
var centerY = y - TextBounds.Height()/2f + TextBounds.Height()*BaselineRatio;
canvas.Rotate(rotation, centerX, centerY);
}
canvas.DrawText(_icon, x - TextBounds.Left, y - TextBounds.Bottom + TextBounds.Height()*BaselineRatio,
paint);
canvas.Restore();
}
示例7: Draw
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
{
ApplyCustomTypeFace(paint, type);
paint.GetTextBounds(icon, 0, 1, TEXT_BOUNDS);
canvas.Save();
float baselineRatio = baselineAligned ? 0f : BASELINE_RATIO;
if (rotate)
{
long time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
float rotation = (time - rotationStartTime) / (float)ROTATION_DURATION * 360f;
float centerX = x + TEXT_BOUNDS.Width() / 2f;
float centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
canvas.Rotate(rotation, centerX, centerY);
}
canvas.DrawText(icon,
x - TEXT_BOUNDS.Left,
y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
canvas.Restore();
}
示例8: OnDraw
protected override void OnDraw (Canvas canvas)
{
// All of our positions are using our internal coordinate system.
// Instead of translating
// them we let Canvas do the work for us.
canvas.Translate(_translationOffsetX, _translationOffsetY);
float progressRotation = GetCurrentRotation();
// draw the background
if (!_overrdraw) {
canvas.DrawArc(_circleBounds, 270, -(360 - progressRotation), false,
_backgroundColorPaint);
}
// draw the progress or a full circle if overdraw is true
canvas.DrawArc(_circleBounds, 270, _overrdraw ? 360 : progressRotation, false,
_progressColorPaint);
// draw the marker at the correct rotated position
if (_isMarkerEnabled) {
float markerRotation = GetMarkerRotation();
canvas.Save();
canvas.Rotate(markerRotation - 90);
canvas.DrawLine((float) (_thumbPosX + _thumbRadius / 2 * 1.4), _thumbPosY,
(float) (_thumbPosX - _thumbRadius / 2 * 1.4), _thumbPosY, _markerColorPaint);
canvas.Restore();
}
if (IsThumbEnabled()) {
// draw the thumb square at the correct rotated position
canvas.Save();
canvas.Rotate(progressRotation - 90);
// rotate the square by 45 degrees
canvas.Rotate(45, _thumbPosX, _thumbPosY);
_squareRect.Left = _thumbPosX - _thumbRadius / 3;
_squareRect.Right = _thumbPosX + _thumbRadius / 3;
_squareRect.Top = _thumbPosY - _thumbRadius / 3;
_squareRect.Bottom = _thumbPosY + _thumbRadius / 3;
canvas.DrawRect(_squareRect, _thumbColorPaint);
canvas.Restore();
}
}
示例9: DrawTriangle
private void DrawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds)
{
if (mShowArrow)
{
if (mArrow == null)
{
mArrow = new Path();
mArrow.SetFillType(Path.FillType.EvenOdd);
}
else
{
mArrow.Reset();
}
float x = (float)(RingCenterRadius * Math.Cos(0) + bounds.ExactCenterX());
float y = (float)(RingCenterRadius * Math.Sin(0) + bounds.ExactCenterY());
mArrow.MoveTo(0, 0);
mArrow.LineTo((mArrowWidth) * mArrowScale, 0);
mArrow.LineTo(((mArrowWidth) * mArrowScale / 2), (mArrowHeight * mArrowScale));
mArrow.Offset(x - ((mArrowWidth) * mArrowScale / 2), y);
mArrow.Close();
mArrowPaint.Color = mColors[mColorIndex];
c.Rotate(startAngle + (sweepAngle < 0 ? 0 : sweepAngle) - ARROW_OFFSET_ANGLE, bounds.ExactCenterX(), bounds.ExactCenterY());
c.DrawPath(mArrow, mArrowPaint);
}
}
示例10: DoDraw
/// <summary>
/// Draws the ship, fuel/speed bars, and background to the provided
/// Canvas.
/// </summary>
private void DoDraw(Canvas canvas)
{
// Draw the background image. Operations on the Canvas accumulate
// so this is like clearing the screen.
canvas.DrawBitmap(mBackgroundImage, 0, 0, null);
int yTop = mCanvasHeight - ((int) mY + mLanderHeight / 2);
int xLeft = (int) mX - mLanderWidth / 2;
// Draw the fuel gauge
int fuelWidth = (int)(UI_BAR * mFuel / PHYS_FUEL_MAX);
mScratchRect.Set(4, 4, 4 + fuelWidth, 4 + UI_BAR_HEIGHT);
canvas.DrawRect(mScratchRect, mLinePaint);
// Draw the speed gauge, with a two-tone effect
double speed = Math.Sqrt(mDX * mDX + mDY * mDY);
int speedWidth = (int)(UI_BAR * speed / PHYS_SPEED_MAX);
if (speed <= mGoalSpeed)
{
mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
canvas.DrawRect(mScratchRect, mLinePaint);
}
else
{
// Draw the bad color in back, with the good color in front of
// it
mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
canvas.DrawRect(mScratchRect, mLinePaintBad);
int goalWidth = (UI_BAR * mGoalSpeed / PHYS_SPEED_MAX);
mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + goalWidth, 4 + UI_BAR_HEIGHT);
canvas.DrawRect(mScratchRect, mLinePaint);
}
// Draw the landing pad
canvas.DrawLine(mGoalX, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mGoalX + mGoalWidth, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mLinePaint);
// Draw the ship with its current rotation
canvas.Save();
canvas.Rotate((float) mHeading, (float) mX, mCanvasHeight - (float) mY);
if (mMode == STATE_LOSE)
{
mCrashedImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
mCrashedImage.Draw(canvas);
}
else if (mEngineFiring)
{
mFiringImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
mFiringImage.Draw(canvas);
}
else
{
mLanderImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
mLanderImage.Draw(canvas);
}
canvas.Restore();
}
示例11: OnDraw
protected override void OnDraw (Canvas canvas)
{
base.OnDraw (canvas);
// Clear screen to pink.
paint.Color = new Color (255, 204, 204);
canvas.DrawPaint (paint);
// Overall transforms to shift (0, 0) to center and scale.
canvas.Translate (this.Width / 2, this.Height / 2);
float scale = Math.Min (this.Width, this.Height) / 2.0f / 100;
canvas.Scale (scale, scale);
// Attributes for tick marks.
paint.Color = Color.Black;
paint.StrokeCap = Paint.Cap.Round;
paint.SetStyle (Paint.Style.Stroke);
// Set line dash to draw tick marks for every minute.
paint.StrokeWidth = 3;
paint.SetPathEffect (minuteTickDashEffect);
canvas.DrawPath (tickMarks, paint);
// Set line dash to draw tick marks for every hour.
paint.StrokeWidth = 6;
paint.SetPathEffect (hourTickDashEffect);
canvas.DrawPath (tickMarks, paint);
// Set attributes common to all clock hands.
Color strokeColor = Color.Black;
Color fillColor = Color.Blue;
paint.StrokeWidth = 2;
paint.SetPathEffect (null);
// Draw hour hand.
canvas.Save ();
canvas.Rotate (this.hourAngle);
paint.Color = fillColor;
paint.SetStyle (Paint.Style.Fill);
canvas.DrawPath (hourHand, paint);
paint.Color = strokeColor;
paint.SetStyle (Paint.Style.Stroke);
canvas.DrawPath (hourHand, paint);
canvas.Restore ();
// Draw minute hand.
canvas.Save ();
canvas.Rotate (this.minuteAngle);
paint.Color = fillColor;
paint.SetStyle (Paint.Style.Fill);
canvas.DrawPath (minuteHand, paint);
paint.Color = strokeColor;
paint.SetStyle (Paint.Style.Stroke);
canvas.DrawPath (minuteHand, paint);
canvas.Restore ();
// Draw second hand.
canvas.Save ();
canvas.Rotate (this.secondAngle);
paint.Color = strokeColor;
paint.SetStyle (Paint.Style.Stroke);
canvas.DrawPath (secondHand, paint);
canvas.Restore ();
}
示例12: OnDraw
protected override void OnDraw(Canvas canvas)
{
Paint paint = mPaint;
canvas.DrawColor (Color.White);
paint.AntiAlias = true;
paint.Color = Color.Black;
paint.SetStyle (Paint.Style.Fill);
int w = canvas.Width;
int h = canvas.Height;
int cx = w / 2;
int cy = h / 2;
canvas.Translate (cx, cy);
if (compass.mValues != null)
canvas.Rotate (-compass.mValues[0]);
canvas.DrawPath (mPath, mPaint);
}
示例13: OnDraw
protected override void OnDraw(Canvas canvas)
{
// All of our positions are using our internal coordinate system.
// Instead of translating
// them we let Canvas do the work for us.
canvas.Translate(translationOffsetX, translationOffsetY);
var progressRotation = CurrentRoatation;
//draw the background
if (!overdraw)
{
canvas.DrawArc(circleBounds, 270, -(360 - progressRotation), false, backgroundColorPaint);
}
//draw the progress or a full circle if overdraw is true
canvas.DrawArc(circleBounds, 270, overdraw ? 360 : progressRotation, false, progressColorPaint);
//draw the marker at the correct rortated position
if (IsMarkerEnabled)
{
var markerRotation = MarkerRotation;
canvas.Save();
canvas.Rotate(markerRotation - 90);
canvas.DrawLine(thumbPosX + thumbRadius / 2.0f * 1.4f, thumbPosY,
thumbPosX - thumbRadius / 2.0f * 1.4f, thumbPosY, markerColorPaint);
canvas.Restore();
}
//draw the thumb square at the correct rotated position
canvas.Save();
canvas.Rotate(progressRotation - 90);
//rotate the square by 45 degrees
canvas.Rotate(45, thumbPosX, thumbPosY);
var rect = new RectF();
rect.Left = thumbPosX - thumbRadius / 3.0f;
rect.Right = thumbPosX + thumbRadius / 3.0f;
rect.Top = thumbPosY - thumbRadius / 3.0f;
rect.Bottom = thumbPosY + thumbRadius / 3.0f;
canvas.DrawRect(rect, thumbColorPaint);
canvas.Restore();
}
示例14: OnDraw
protected override void OnDraw(Canvas canvas)
{
lock (this) {
if (mBitmap != null) {
Path path = mPath;
int outer = new Color (192, 192, 192);
int inner = new Color (255, 112, 16);
if (mLastX >= mMaxX) {
mLastX = 0;
Canvas cavas = mCanvas;
float yoffset = mYOffset;
float maxx = mMaxX;
float oneG = SensorManager.StandardGravity * mScale[0];
paint.Color = new Color (170, 170, 170);
cavas.DrawColor (Color.Black);
cavas.DrawLine (0, yoffset, maxx, yoffset, paint);
cavas.DrawLine (0, yoffset + oneG, maxx, yoffset + oneG, paint);
cavas.DrawLine (0, yoffset - oneG, maxx, yoffset - oneG, paint);
}
canvas.DrawBitmap (mBitmap, 0, 0, null);
float[] values = mOrientationValues;
if (mWidth < mHeight) {
float w0 = mWidth * 0.333333f;
float w = w0 - 32;
float x = w0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.Save (SaveFlags.Matrix);
canvas.Translate (x, w * 0.5f + 4.0f);
canvas.Save (SaveFlags.Matrix);
paint.Color = outer;
canvas.Scale (w, w);
canvas.DrawOval (mRect, paint);
canvas.Restore ();
canvas.Scale (w - 5, w - 5);
paint.Color = inner;
canvas.Rotate (-values[i]);
canvas.DrawPath (path, paint);
canvas.Restore ();
x += w0;
}
} else {
float h0 = mHeight * 0.333333f;
float h = h0 - 32;
float y = h0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.Save (SaveFlags.Matrix);
canvas.Translate (mWidth - (h * 0.5f + 4.0f), y);
canvas.Save (SaveFlags.Matrix);
paint.Color = outer;
canvas.Scale (h, h);
canvas.DrawOval (mRect, paint);
canvas.Restore ();
canvas.Scale (h - 5, h - 5);
paint.Color = inner;
canvas.Rotate (-values[i]);
canvas.DrawPath (path, paint);
canvas.Restore ();
y += h0;
}
}
}
}
}
示例15: onDraw
protected void onDraw(Canvas c)
{
c.Rotate (-90);
c.Translate (-Height, 0);
base.OnDraw (c);
}