public static Bitmap getRoundedShape(ViewProps props) { Bitmap scaleBitmapImage = props.image; int targetWidth = props.size; int targetHeight = props.size; Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return(targetBitmap); }
public void DrawStopwatch(Canvas canvas) { canvas.Save(); canvas.Translate(Width / 2F, Height / 2F); var tickMarks = new Path(); tickMarks.AddCircle(0, 0, 90, Path.Direction.Cw); var scale = Math.Min(Width, Height) / 2F / 120; canvas.Scale(scale, scale); var paint = new Paint { StrokeCap = Paint.Cap.Square, Color = new Color(240, 240, 240) }; paint.SetStyle(Paint.Style.Stroke); paint.StrokeWidth = 3; paint.SetPathEffect(MinuteDashEffect); canvas.DrawPath(tickMarks, paint); paint.Color = new Color(240, 240, 240); paint.StrokeWidth = 4; paint.SetPathEffect(FifthMinuteDashEffect); canvas.DrawPath(tickMarks, paint); }
public static Bitmap GetRoundedShape(Bitmap scaleBitmapImage, Context context) { if (scaleBitmapImage == null) { return(BitmapFactory.DecodeResource(context.Resources, Android.Resource.Drawable.IcMenuGallery)); } int targetWidth = 220; int targetHeight = 284; Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2 - 20, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return(targetBitmap); }
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) { try { int targetWidth = 480; int targetHeight = 480; Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return(targetBitmap); } catch (Exception) { return(scaleBitmapImage); } }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); // Create path for circle border path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); //Properly dispose paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { Console.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
/// <summary> /// /// </summary> /// <param name="canvas"></param> /// <param name="child"></param> /// <param name="drawingTime"></param> /// <returns></returns> protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = ((CircleImage)Element).BorderThickness; radius -= strokeWidth / 2; var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var paint = new Paint(); paint.AntiAlias = true; paint.SetStyle(Paint.Style.Fill); paint.Color = ((CircleImage)Element).FillColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var thickness = ((CircleImage)Element).BorderThickness; if(thickness > 0.0f) { paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = thickness; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((CircleImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var borderThickness = (float)((CircleImage)Element).BorderThickness; int strokeWidth = 0; if (borderThickness > 0) { var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density; strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f); } radius -= strokeWidth / 2; var path = new Path(); path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var paint = new Paint(); paint.AntiAlias = true; paint.SetStyle(Paint.Style.Fill); paint.Color = ((CircleImage)Element).FillColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle((float) Width / 2, (float) Height / 2, radius, Path.Direction.Ccw); if (strokeWidth > 0.0f) { paint = new Paint {AntiAlias = true, StrokeWidth = strokeWidth}; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((CircleImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
/// <summary> /// Draw one child of this View Group. /// </summary> /// <param name="canvas">The canvas on which to draw the child</param> /// <param name="child">Who to draw</param> /// <param name="drawingTime">The time at which draw is occurring</param> /// <returns>To be added.</returns> /// <since version="Added in API level 1" /> /// <remarks><para tool="javadoc-to-mdoc">Draw one child of this View Group. This method is responsible for getting /// the canvas in the right state. This includes clipping, translating so /// that the child's scrolled origin is at 0, 0, and applying any animation /// transformations.</para> /// <para tool="javadoc-to-mdoc"> /// <format type="text/html"> /// <a href="http://developer.android.com/reference/android/view/ViewGroup.html#drawChild(android.graphics.Canvas, android.view.View, long)" target="_blank">[Android Documentation]</a> /// </format> /// </para></remarks> protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { if (this.Element.Aspect != Aspect.AspectFit) { return base.DrawChild(canvas, child, drawingTime); } using (var path = new Path()) { path.AddCircle(Width / 2, Height / 2, (Math.Min(Width, Height) - 10) / 2, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } return base.DrawChild(canvas, child, drawingTime); }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { // Extract properties var source = (CircularImage)Element; var borderWidth = source.BorderWidth; var borderColor = source.BorderColor.ToAndroid(); var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); // Create path for circle border path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = borderWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = borderColor; canvas.DrawPath(path, paint); //Properly dispose paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
public override void Draw(Android.Graphics.Canvas canvas) { try { int width = this.Width - this.PaddingLeft - this.PaddingRight; int height = this.Height - this.PaddingBottom - this.PaddingTop; var radius = Math.Min(width, height) / 2; //var strokeWidth = ((float)(5 * Math.Min(width, height))) / 100; //radius -= (int)Math.Round(strokeWidth / 2); // A revoir: Est-ce que c'est bien centré avec les padding? Path path = new Path(); path.AddCircle(this.PaddingLeft + (width / 2), this.PaddingTop + (height / 2), radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); base.Draw(canvas); canvas.Restore(); //path = new Path(); //path.AddCircle(this.PaddingLeft + (width / 2), this.PaddingTop + (height / 2), radius, Path.Direction.Ccw); //var paint = new Paint(); //paint.AntiAlias = true; //paint.StrokeWidth = strokeWidth; //paint.SetStyle(Paint.Style.Stroke); //paint.Color = Color.Black; //canvas.DrawPath(path, paint); //paint.Dispose(); path.Dispose(); return; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } base.Draw(canvas); }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; Path path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { } return base.DrawChild(canvas, child, drawingTime); }
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); }
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int targetWidth, int targetHeight) { Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime) { try { var element = (RoundedImage)Element; var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); // Create path for circle border path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; //TODO look for a correct way to assign the BorderWidth depending of the screen dpi paint.StrokeWidth = (float)element.BorderWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = element.BorderColor.ToAndroid(); canvas.DrawPath(path, paint); //Properly dispose paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { //Why this happend Console.WriteLine(ex.Message); } return base.DrawChild(canvas, child, drawingTime); }
private void Initialize() { mPath = new Path(); mPath.AddCircle(40, 40, 45, Path.Direction.Ccw); mPath.AddCircle(80, 80, 45, Path.Direction.Ccw); }
void drawLines (Canvas canvas, Paint paint) { float x, y; // Draw curved graph line var whiteAlpha25 = Color.Argb (64, 255, 255, 255); //var whiteAlpha70 = Color.Argb (64, 255, 255, 255); var start = new PointF (); var end = new PointF (); using (Path path = new Path ()) { var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2); for (int i = 0; i < count; i++) { // adjusted index var ai = i; double temp; if (hourly) { temp = HourlyTemps [ai]; } else { // reset start when switching from highs to lows if (i == Forecasts.Count) start = new PointF (); var highs = i < Forecasts.Count; ai = highs ? i : i - Forecasts.Count; temp = highs ? HighTemps [ai] : LowTemps [ai]; } var percent = ((float)temp - scaleLow) / scaleRange; x = padding + inset + (ai * scaleX); y = graphRect.Bottom - (graphRect.Height () * percent); end = new PointF (x, y); if (!hourly) { path.AddCircle (end.X - lineWidth, end.Y - lineWidth, lineWidth / 2, Path.Direction.Cw); } if (start.IsEmpty ()) { path.MoveTo (end); } else { path.MoveTo (start); if (hourly) { path.LineTo (end); } else { var diff = (end.X - start.X) / 2; path.CubicTo (end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y); } } start = end; } paint.Color = whiteAlpha25; paint.StrokeWidth = lineWidth; paint.SetStyle (Paint.Style.Stroke); canvas.DrawPath (path, paint); } }
private void RenderBack(Canvas canvas) { var Path = new Path(); var viewRadius = GetViewRadius (); Path.AddCircle (drawingArea.CenterX(), drawingArea.CenterY(), viewRadius, Path.Direction.Ccw); canvas.DrawPath (Path, backStrokePaint); }
public void AddCircle(float xCenter, float yCenter, float radius) { path.AddCircle(xCenter, yCenter, radius, Android.Graphics.Path.Direction.Cw); }
private void DrawRing(Canvas c) { var sc = c.Save(); c.Rotate(-this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //������Բ Path ����һ�� Բ����ʾ����, ���ڿ���Բ var pInner = new Path(); pInner.AddCircle(cx, cy, this.BitmapRadius + SPACE / 2, Path.Direction.Cw); var pOut = new Path(); pOut.AddCircle(cx, cy, this.Radius, Path.Direction.Cw); c.ClipPath(pOut); c.ClipPath(pInner, Region.Op.Difference); //var color = new Color((int)(DateTime.Now.Ticks % 0xFFFFFFFF)); //c.DrawColor(color); //�ýǶȽ��������Բ�ķ�Χ var g = new SweepGradient(cx, cy, Color.Green, Color.Transparent); var paint = new Paint(); paint.SetShader(g); c.DrawCircle(cx, cy, this.Radius, paint); c.RestoreToCount(sc); }
private void DrawBitmap(Canvas c, Bitmap bmp) { var sc = c.Save(); this.Degree = this.Degree % 360 + DEGREE_STEP; //Ҫ����ת����ͼ����Ч�� c.Rotate(this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //����ʾ��Χ, ָ���뾶��Բ var path = new Path(); path.AddCircle(cx, cy, this.BitmapRadius, Path.Direction.Cw); c.ClipPath(path); c.DrawColor(Color.White); //ͼƬ�Ļ��Ʒ�Χ var w = (this.ShowType == ShowTypes.Inner ? this.IWH : this.OWH) / 2; var rect = new Rect(cx - w, cy - w, cx + w, cy + w); //����ͼƬ var paint = new Paint(); //srcΪnull, ��������ͼƬ��ΪԴ c.DrawBitmap(bmp, null, rect, paint); c.RestoreToCount(sc); }
void DrawWater(Canvas canvas) { canvas.Save (); var circle = new Path (); circle.AddCircle (Width / 2, Height / 2, Height / 2, Path.Direction.Ccw); circle.Close (); canvas.ClipPath (circle); wavy.Draw (canvas); canvas.Restore (); }
/// <summary> /// Draw one child of this View Group. /// </summary> /// <param name="canvas">The canvas on which to draw the child</param> /// <param name="child">Who to draw</param> /// <param name="drawingTime">The time at which draw is occurring</param> /// <returns>To be added.</returns> /// <since version="Added in API level 1" /> /// <remarks><para tool="javadoc-to-mdoc">Draw one child of this View Group. This method is responsible for getting /// the canvas in the right state. This includes clipping, translating so /// that the child's scrolled origin is at 0, 0, and applying any animation /// transformations.</para> /// <para tool="javadoc-to-mdoc"> /// <format type="text/html"> /// <a href="http://developer.android.com/reference/android/view/ViewGroup.html#drawChild(android.graphics.Canvas, android.view.View, long)" target="_blank">[Android Documentation]</a> /// </format> /// </para></remarks> protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { if (this.Element.Aspect == Aspect.AspectFit) { var radius = Math.Min(Width, Height)/2; var strokeWidth = 10; radius -= strokeWidth/2; Path path = new Path(); path.AddCircle(Width/2, Height/2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); path.Dispose(); return result; } return base.DrawChild(canvas, child, drawingTime); }
protected override void DispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { base.DispatchDraw(canvas); return; } bool recalculatedCling = mShowcaseDrawer.CalculateShowcaseRect(showcaseX, showcaseY); bool recalculateText = recalculatedCling || mAlteredText; mAlteredText = false; if (Build.VERSION.SdkInt <= BuildVersionCodes.Honeycomb && !mHasNoTarget) { var path = new Path(); path.AddCircle(showcaseX, showcaseY, showcaseRadius, Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); } //Draw background color canvas.DrawColor(mBackgroundColor); // Draw the showcase drawable if (!mHasNoTarget) { mShowcaseDrawer.DrawShowcase(canvas, showcaseX, showcaseY, scaleMultiplier, showcaseRadius); } // Draw the text on the screen, recalculating its position if necessary if (recalculateText) { mTextDrawer.CalculateTextPosition(canvas.Width, canvas.Height, this); } mTextDrawer.Draw(canvas, recalculateText); base.DispatchDraw(canvas); }
protected override void OnDraw(Canvas ca) { if (fullImage == null || shouldUpdate) { fullImage = Bitmap.CreateBitmap (Width, Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(fullImage); String max = (int)maxY+"";// used to display max String min = (int)minY+"";// used to display min paint.Reset (); Path path = new Path(); float bottomPadding = 1, topPadding = 0; float sidePadding = 10; if (this.showMinAndMax) sidePadding = txtPaint.MeasureText(max); float usableHeight = Height - bottomPadding - topPadding; float usableWidth = Width - sidePadding*2; float lineSpace = usableHeight/10; int lineCount = 0; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY (); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); if (lineCount == lineToFill){ paint.Color = Color.White; paint.Alpha = 30; paint.StrokeWidth = 2; for (int i = 10; i-Width < Height; i = i+20){ canvas.DrawLine(i, Height-bottomPadding, 0, Height-bottomPadding-i, paint); } paint.Reset(); paint.SetXfermode (new PorterDuffXfermode (Android.Graphics.PorterDuff.Mode.Clear)); foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minY)/(maxYd - minYd); float xPercent = (p.getX()-minX)/(maxXd - minXd); if (count == 0){ lastXPixels = sidePadding + (xPercent*usableWidth); lastYPixels = Height - bottomPadding - (usableHeight*yPercent); path.MoveTo(lastXPixels, lastYPixels); } else { newXPixels = sidePadding + (xPercent*usableWidth); newYPixels = Height - bottomPadding - (usableHeight*yPercent); path.LineTo(newXPixels, newYPixels); Path pa = new Path(); pa.MoveTo(lastXPixels, lastYPixels); pa.LineTo(newXPixels, newYPixels); pa.LineTo(newXPixels, 0); pa.LineTo(lastXPixels, 0); pa.Close(); canvas.DrawPath(pa, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } path.Reset(); path.MoveTo(0, Height-bottomPadding); path.LineTo(sidePadding, Height-bottomPadding); path.LineTo(sidePadding, 0); path.LineTo(0, 0); path.Close(); canvas.DrawPath(path, paint); path.Reset(); path.MoveTo(Width, Height-bottomPadding); path.LineTo(Width-sidePadding, Height-bottomPadding); path.LineTo(Width-sidePadding, 0); path.LineTo(Width, 0); path.Close(); canvas.DrawPath(path, paint); } lineCount++; } paint.Reset(); paint.Color = Color.White; //paint.setColor(this.gridColor); paint.Alpha = 50; paint.AntiAlias = true; canvas.DrawLine(sidePadding, Height - bottomPadding, Width, Height-bottomPadding, paint); if(this.showHorizontalGrid1) for(int i=1;i<=10;i++) { canvas.DrawLine(sidePadding, Height - bottomPadding-(i*lineSpace), Width, Height-bottomPadding-(i*lineSpace), paint); } paint.Alpha = 255; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minY)/(maxYd - minYd); float xPercent = (p.getX()-minX)/(maxXd - minXd); if (count == 0){ lastXPixels = sidePadding + (xPercent*usableWidth); lastYPixels = Height - bottomPadding - (usableHeight*yPercent); } else { newXPixels = sidePadding + (xPercent*usableWidth); newYPixels = Height - bottomPadding - (usableHeight*yPercent); canvas.DrawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } } int pointCount = 0; foreach (Line line in lines) { float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; paint.StrokeCap = Paint.Cap.Round; if (line.isShowingPoints()){ foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minYd)/(maxYd - minYd); float xPercent = (p.getX()-minXd)/(maxXd - minXd); float xPixels = sidePadding + (xPercent*usableWidth); float yPixels = Height - bottomPadding - (usableHeight*yPercent); paint.Color = Color.Gray; canvas.DrawCircle(xPixels, yPixels, 10, paint); paint.Color = Color.White; canvas.DrawCircle(xPixels, yPixels, 5, paint); Path path2 = new Path(); path2.AddCircle(xPixels, yPixels, 30, Android.Graphics.Path.Direction.Cw); p.setPath(path2); p.setRegion(new Region((int)(xPixels-30), (int)(yPixels-30), (int)(xPixels+30), (int)(yPixels+30))); if (indexSelected == pointCount && listener != null){ paint.Color=Color.ParseColor("#33B5E5"); paint.Alpha = 100; canvas.DrawPath(p.getPath(), paint); paint.Alpha = 255; } pointCount++; } } } shouldUpdate = false; if (this.showMinAndMax) { ca.DrawText(max, 0, txtPaint.TextSize, txtPaint); ca.DrawText(min,0,this.Height,txtPaint); } } ca.DrawBitmap(fullImage, 0, 0, null); }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Android.Graphics.Path(); path.AddCircle(Width / 2, Height / 2, radius, Android.Graphics.Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); var uriImageSource = (UriImageSource)Element.Source; WebRequest request = HttpWebRequest.Create(uriImageSource.Uri.AbsoluteUri); request.Timeout = 10000; WebResponse response = request.GetResponse(); Stream inputStream = response.GetResponseStream(); Bitmap mainBitmap = BitmapFactory.DecodeStream(inputStream); /* * float ratio = Math.Min( * 25 / mainBitmap.Width, * 25 / mainBitmap.Height); * int width = (int)Math.Round((float)ratio * mainBitmap.Width); * int height = (int)Math.Round((float)ratio * mainBitmap.Height); */ Bitmap newBitmap = Bitmap.CreateScaledBitmap(mainBitmap, 150, 150, true); canvas.DrawBitmap(newBitmap, 0, 0, null); canvas.Restore(); // Create path for circle border path = new Android.Graphics.Path(); path.AddCircle(Width / 2, Height / 2, radius, Android.Graphics.Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return(result); } catch (Exception ex) { //Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
void CreatePath() { droidGraphics.Path path = new droidGraphics.Path(); path.AddCircle(0, 0, 1, droidGraphics.Path.Direction.Cw); // TODO: Is direction correct? Path = path; }
internal void Draw(Canvas canvas, bool isRound) { if (Hidden) { return; } canvas.Save(); var resizerPaint = new Paint { Color = new Color(255, 255, 255, 200) }; //if (!Focused) //{ // outlinePaint.Color = Color.White; // canvas.DrawRect(DrawRect, outlinePaint); // //canvas.DrawCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width(), resizerPaint); //} //else //{ Rect viewDrawingRect = new Rect(); context.GetDrawingRect(viewDrawingRect); outlinePaint.Color = Color.White;// new Color(0XFF, 0xFF, 0x8A, 0x00); focusPaint.Color = new Color(50, 50, 50, 125); Path path = new Path(); if (isRound) { path.AddCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width() / 2, Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint); } else { path.AddRect(new RectF(DrawRect), Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); canvas.DrawRect(viewDrawingRect, focusPaint); } //canvas.ClipPath(path, Region.Op.Difference); //if (isRound) // canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint); //else // canvas.DrawRect(viewDrawingRect, focusPaint); canvas.Restore(); canvas.DrawPath(path, outlinePaint); var resizerTriangle = new Path(); var resizerOffset = 4; var triangleSize = resizerSize + resizerOffset; resizerTriangle.MoveTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - triangleSize); resizerTriangle.LineTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - resizerOffset); resizerTriangle.LineTo(DrawRect.Right - triangleSize, DrawRect.Bottom - resizerOffset); resizerPaint.SetStyle(Paint.Style.Fill); canvas.DrawPath(resizerTriangle, resizerPaint); if (isRound) { // Draw the rectangle around the round cropper var roundCropperRectangle = new Path(); roundCropperRectangle.MoveTo(DrawRect.Left, DrawRect.Top); roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Top); roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Bottom); roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Bottom); roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Top); resizerPaint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(roundCropperRectangle, resizerPaint); } }