protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mTempBounds; arcBounds.Set(bounds); mPaint.Alpha = MAX_ALPHA; mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mCurrentColor); if (mSunCoordinateY < mInitSun_MoonCoordinateY) { canvas.DrawCircle(arcBounds.CenterX(), mSunCoordinateY, mSun_MoonRadius, mPaint); } if (mMoonCoordinateY < mInitSun_MoonCoordinateY) { int moonSaveCount = canvas.Save(); canvas.Rotate(mMoonRotation, arcBounds.CenterX(), mMoonCoordinateY); canvas.DrawPath(CreateMoonPath(arcBounds.CenterX(), mMoonCoordinateY), mPaint); canvas.RestoreToCount(moonSaveCount); } for (int i = 0; i < mSunRayCount; i++) { int sunRaySaveCount = canvas.Save(); //rotate 45 degrees can change the direction of 0 degrees to 1:30 clock //-mSunRayRotation means reverse rotation canvas.Rotate(45 - mSunRayRotation + (mIsExpandSunRay ? i : MAX_SUN_RAY_COUNT - i) * DEGREE_360 / MAX_SUN_RAY_COUNT, arcBounds.CenterX(), mSunCoordinateY); canvas.DrawLine(arcBounds.CenterX(), mSunRayStartCoordinateY, arcBounds.CenterX(), mSunRayEndCoordinateY, mPaint); canvas.RestoreToCount(sunRaySaveCount); } if (mShowStar) { if (mStarHolders.Count == 0) { InitStarHolders(arcBounds); } for (int i = 0; i < mStarHolders.Count; i++) { mPaint.SetStyle(Paint.Style.Fill); mPaint.Alpha = mStarHolders[i].mAlpha; canvas.DrawCircle(mStarHolders[i].mCurrentPoint.X, mStarHolders[i].mCurrentPoint.Y, mStarRadius, mPaint); } } canvas.RestoreToCount(saveCount); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { canvas.Rotate(-90); canvas.Translate(-Height, 0); base.OnDraw(canvas); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { if (_isTopDown) { canvas.Translate(Width, 0); canvas.Rotate(90); } else { canvas.Translate(0, Height); canvas.Rotate(-90); } canvas.Translate(CompoundPaddingLeft, ExtendedPaddingTop); Layout.Draw(canvas); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { if (this.Orientation == Orientation.Vertical) { canvas.Rotate(-90); canvas.Translate(-Height, 0); } base.OnDraw(canvas); }
// ExStart:RenderShapeToGraphics public static string RenderShapeToGraphics(string dataDir, Shape shape) { ShapeRenderer r = shape.GetShapeRenderer(); // Find the size that the shape will be rendered to at the specified scale and resolution. Size shapeSizeInPixels = r.GetSizeInPixels(1.0f, 96.0f); // Rotating the shape may result in clipping as the image canvas is too small. Find the longest side // And make sure that the graphics canvas is large enough to compensate for this. int maxSide = System.Math.Max(shapeSizeInPixels.Width, shapeSizeInPixels.Height); using (Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap((int)(maxSide * 1.25), (int)(maxSide * 1.25), Android.Graphics.Bitmap.Config.Argb8888)) { // Rendering to a graphics object means we can specify settings and transformations to be applied to // The shape that is rendered. In our case we will rotate the rendered shape. using (Android.Graphics.Canvas gr = new Android.Graphics.Canvas(bitmap)) { // Clear the shape with the background color of the document. gr.DrawColor(new Android.Graphics.Color(shape.Document.PageColor.ToArgb())); // Center the rotation using translation method below gr.Translate((float)bitmap.Width / 8, (float)bitmap.Height / 2); // Rotate the image by 45 degrees. gr.Rotate(45); // Undo the translation. gr.Translate(-(float)bitmap.Width / 8, -(float)bitmap.Height / 2); // Render the shape onto the graphics object. r.RenderToSize(gr, 0, 0, shapeSizeInPixels.Width, shapeSizeInPixels.Height); } // Save output to file. using (System.IO.FileStream fs = System.IO.File.Create(dataDir + "/RenderToSize_Out.png")) { bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, fs); } } return("\nShape rendered to graphics successfully.\nFile saved at " + dataDir); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mTempBounds; arcBounds.Set(bounds); mPaint.Color = new Color(mColor); //calculate fish clip bounds //clip the width of the fish need to increase mPathDottedLineSize * 1.2f RectF fishRectF = new RectF(mFishHeadPos[0] - mFishWidth / 2.0f - mPathDottedLineSize * 1.2f, mFishHeadPos[1] - mFishHeight / 2.0f, mFishHeadPos[0] + mFishWidth / 2.0f + mPathDottedLineSize * 1.2f, mFishHeadPos[1] + mFishHeight / 2.0f); Matrix matrix = new Matrix(); matrix.PostRotate(mFishRotateDegrees, fishRectF.CenterX(), fishRectF.CenterY()); matrix.MapRect(fishRectF); //draw river int riverSaveCount = canvas.Save(); mPaint.SetStyle(Paint.Style.Stroke); canvas.ClipRect(fishRectF, Region.Op.Difference); canvas.DrawPath(CreateRiverPath(arcBounds), mPaint); canvas.RestoreToCount(riverSaveCount); //draw fish int fishSaveCount = canvas.Save(); mPaint.SetStyle(Paint.Style.Fill); canvas.Rotate(mFishRotateDegrees, mFishHeadPos[0], mFishHeadPos[1]); canvas.ClipPath(CreateFishEyePath(mFishHeadPos[0], mFishHeadPos[1] - mFishHeight * 0.06f), Region.Op.Difference); canvas.DrawPath(CreateFishPath(mFishHeadPos[0], mFishHeadPos[1]), mPaint); canvas.RestoreToCount(fishSaveCount); canvas.RestoreToCount(saveCount); }
public void RotateTransform(float angle) { Flush(); ACanvas.Rotate(angle); }
public override void Draw(Android.Graphics.Canvas canvas) { canvas.Rotate(-90); //Rotating the canvas around (0,0) point of the control canvas.Translate(-Height, 0); //Moving the canvas inside the control rect base.OnDraw(canvas); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mTempBounds; arcBounds.Set(bounds); arcBounds.Inset(mStrokeXInset, mStrokeYInset); mCurrentProgressBounds.Set(arcBounds.Left, arcBounds.Bottom - 2 * mCenterRadius, arcBounds.Right, arcBounds.Bottom); //Draw loading Drawable mLoadingDrawable.SetBounds((int)arcBounds.CenterX() - mLoadingDrawable.IntrinsicWidth / 2, 0, (int)arcBounds.CenterX() + mLoadingDrawable.IntrinsicWidth / 2, mLoadingDrawable.IntrinsicHeight); mLoadingDrawable.Draw(canvas); //Draw progress background float progressInset = mCenterRadius - mProgressCenterRadius; RectF progressRect = new RectF(mCurrentProgressBounds); //sub DEFAULT_STROKE_INTERVAL, otherwise will have a interval between progress background and progress outline progressRect.Inset(progressInset - DEFAULT_STROKE_INTERVAL, progressInset - DEFAULT_STROKE_INTERVAL); mPaint.Color = new Color(mProgressBgColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawRoundRect(progressRect, mProgressCenterRadius, mProgressCenterRadius, mPaint); //Draw progress mPaint.Color = new Color(mProgressColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawPath(CreateProgressPath(mProgress, mProgressCenterRadius, progressRect), mPaint); //Draw leaves for (int i = 0; i < mLeafHolders.Count; i++) { int leafSaveCount = canvas.Save(); LeafHolder leafHolder = mLeafHolders[i]; Rect leafBounds = leafHolder.mLeafRect; canvas.Rotate(leafHolder.mLeafRotation, leafBounds.CenterX(), leafBounds.CenterY()); mLeafDrawable.Bounds = leafBounds; mLeafDrawable.Draw(canvas); canvas.RestoreToCount(leafSaveCount); } //Draw progress background outline, //after Drawing the leaves and then Draw the outline of the progress background can //prevent the leaves from flying to the outside RectF progressOutlineRect = new RectF(mCurrentProgressBounds); float progressOutlineStrokeInset = (mCenterRadius - mProgressCenterRadius) / 2.0f; progressOutlineRect.Inset(progressOutlineStrokeInset, progressOutlineStrokeInset); mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mProgressBgColor); mPaint.StrokeWidth = mCenterRadius - mProgressCenterRadius; canvas.DrawRoundRect(progressOutlineRect, mCenterRadius, mCenterRadius, mPaint); //Draw electric fan outline float electricFanCenterX = arcBounds.Right - mCenterRadius; float electricFanCenterY = arcBounds.Bottom - mCenterRadius; mPaint.Color = new Color(mElectricFanOutlineColor); mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeWidth = mStrokeWidth; canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth / 2.0f, mPaint); //Draw electric background mPaint.Color = new Color(mElectricFanBgColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth + DEFAULT_STROKE_INTERVAL, mPaint); //Draw electric fan int rotateSaveCount = canvas.Save(); canvas.Rotate(mRotation, electricFanCenterX, electricFanCenterY); mElectricFanDrawable.SetBounds((int)(electricFanCenterX - mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY - mElectricFanDrawable.IntrinsicHeight / 2 * mScale), (int)(electricFanCenterX + mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY + mElectricFanDrawable.IntrinsicHeight / 2 * mScale)); mElectricFanDrawable.Draw(canvas); canvas.RestoreToCount(rotateSaveCount); //Draw 100% text if (mScale < 1.0f) { mPaint.TextSize = mTextSize * (1 - mScale); mPaint.Color = new Color(mElectricFanOutlineColor); Rect textRect = new Rect(); mPaint.GetTextBounds(PERCENTAGE_100, 0, PERCENTAGE_100.Length, textRect); canvas.DrawText(PERCENTAGE_100, electricFanCenterX - textRect.Width() / 2.0f, electricFanCenterY + textRect.Height() / 2.0f, mPaint); } canvas.RestoreToCount(saveCount); }